vector 怎么把Bitmap 加到push_back里面的啊

nabasasun 2013-11-01 12:31:03

vector<Bitmap * > ImageList ;
Bitmap *bmp;
bmp=new Bitmap(width,height,PixelFormat32bppARGB);
ImageList.push_back(bmp); //居然失败。







...全文
380 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
myjackheroes 2013-11-14
  • 打赏
  • 举报
回复
引用 20 楼 nabasasun 的回复:
[quote=引用 19 楼 myjackheroes 的回复:] push_back( ptr )是永远不会出错的, 和push_back( 0xFFFFFFFF) 没什么区别. 对于vector来说, 他根本不会管你的指针是否有效. 拿bmp->clone来暗示vector知道你的指针对象有效性, 笑尿了.
那你就去试试看吧,然后再把vector里的东西拷贝到Bitmap的图像上,看看成功否,就知道笑[/quote] vec.push_back( 10 ) -> vec.push_back( LPVOID(10) ) -> vec.push_back( (Bitmap*)(LVPOID)(10) ), Bitmap*只是一个指针,一个整数值,和Bitmap对象根本就没关系, 怎么会失败???我有必要乱讲?
myjackheroes 2013-11-11
  • 打赏
  • 举报
回复
push_back( ptr )是永远不会出错的, 和push_back( 0xFFFFFFFF) 没什么区别. 对于vector来说, 他根本不会管你的指针是否有效. 拿bmp->clone来暗示vector知道你的指针对象有效性, 笑尿了.
lm_whales 2013-11-11
  • 打赏
  • 举报
回复
引用 18 楼 nabasasun 的回复:
[quote=引用 17 楼 lm_whales 的回复:] 这个是不是有个写时拷贝的问题。 绘出的图形暂时还在,bmpDC上,没有存到 bmp 内部; 估计,bmp->Clone 有个写操作,就会启动写时拷贝,数据就存储到位图上了。
第二个就是纯粹的括号,没有任何操作,我不知道为什么,总之就是存不进图形[/quote] 这个GDI+ 不是很熟 GDI函数,好像必须从DC上卸下,否则可能不会绘制在为图上-----这就是写时拷贝,类似懒惰删除的做法。 GDI+,不知是否需要detach 或者需要别的操作,让绘制到bmpDC上的图形,存储到位图上来。 是否需要 GdipFlush 一下?
nabasasun 2013-11-11
  • 打赏
  • 举报
回复
引用 19 楼 myjackheroes 的回复:
push_back( ptr )是永远不会出错的, 和push_back( 0xFFFFFFFF) 没什么区别. 对于vector来说, 他根本不会管你的指针是否有效. 拿bmp->clone来暗示vector知道你的指针对象有效性, 笑尿了.
那你就去试试看吧,然后再把vector里的东西拷贝到Bitmap的图像上,看看成功否,就知道笑
nabasasun 2013-11-10
  • 打赏
  • 举报
回复
引用 13 楼 lm_whales 的回复:
可能是代码被优化掉了
我是使用DEBUG来编译的,应该不优化
nabasasun 2013-11-10
  • 打赏
  • 举报
回复
引用 17 楼 lm_whales 的回复:
这个是不是有个写时拷贝的问题。 绘出的图形暂时还在,bmpDC上,没有存到 bmp 内部; 估计,bmp->Clone 有个写操作,就会启动写时拷贝,数据就存储到位图上了。
第二个就是纯粹的括号,没有任何操作,我不知道为什么,总之就是存不进图形
lm_whales 2013-11-10
  • 打赏
  • 举报
回复
这里只有这么点信息,而且都不会有问题。 也没看到拷贝图片的代码, 拷贝图片的时候没有任何效果,的原因,无从查起。
lm_whales 2013-11-10
  • 打赏
  • 举报
回复
这个是不是有个写时拷贝的问题。 绘出的图形暂时还在,bmpDC上,没有存到 bmp 内部; 估计,bmp->Clone 有个写操作,就会启动写时拷贝,数据就存储到位图上了。
nabasasun 2013-11-10
  • 打赏
  • 举报
回复
引用 15 楼 lm_whales 的回复:
这里只有这么点信息,而且都不会有问题。 也没看到拷贝图片的代码, 拷贝图片的时候没有任何效果,的原因,无从查起。

vector<Bitmap * > ImageList ;
Bitmap *bmp;
Bitmap *image;
bmp=new Bitmap(width,height,PixelFormat32bppARGB);
image=new Bitmap(width,height,PixelFormat32bppARGB);



Graphics g(pDC->GetSafeHdc());  
Graphics bmpDC(bmp);

bmpDC.Clear(Color(255,255,255,255));

bmpDC.DrawImage(image,0,0);
 
//在这里画东西
 

ImageList.push_back(bmp->Clone(Rect(0,0,bmp->GetWidth(),bmp->GetHeight()),PixelFormatDontCare)); //成功


ImageList.push_back(bmp);  //失败

lm_whales 2013-11-09
  • 打赏
  • 举报
回复
可能是代码被优化掉了
nabasasun 2013-11-09
  • 打赏
  • 举报
回复
引用 11 楼 lm_whales 的回复:
Bitmap::Bitmap(IDirectDrawSurface7*)
Bitmap::Bitmap(INT,INT,Grpaphics*)
Bitmap::Bitmap(BITMAPINFO*,VOID*)
Bitmap::Bitmap(INT,INT,PixelFormat)//这个没有初始化数据。估计全黑
Bitmap::Bitmap(HBITMAP,HPALETTE)
Bitmap::Bitmap(INT,INT,INT,PixelFormat,BYTE*)//这是有数据的,BYTE* 类型的参数是数据。
Bitmap::Bitmap(WCHAR*,BOOL)
Bitmap::Bitmap(HINSTANCE,WCHAR*)
Bitmap::Bitmap(HICON)
Bitmap::Bitmap(IStream*,BOOL)
你的这个没有初始化数据,需要自己填充,或设置吧!
填充做过的,白色,因为这里我只放了主要的代码,但是还是加不到vector里,用拷贝的方式就可以加进去,真奇怪
lm_whales 2013-11-09
  • 打赏
  • 举报
回复
Bitmap::Bitmap(IDirectDrawSurface7*)
Bitmap::Bitmap(INT,INT,Grpaphics*)
Bitmap::Bitmap(BITMAPINFO*,VOID*)
Bitmap::Bitmap(INT,INT,PixelFormat)//这个没有初始化数据。估计全黑
Bitmap::Bitmap(HBITMAP,HPALETTE)
Bitmap::Bitmap(INT,INT,INT,PixelFormat,BYTE*)//这是有数据的,BYTE* 类型的参数是数据。
Bitmap::Bitmap(WCHAR*,BOOL)
Bitmap::Bitmap(HINSTANCE,WCHAR*)
Bitmap::Bitmap(HICON)
Bitmap::Bitmap(IStream*,BOOL)
你的这个没有初始化数据,需要自己填充,或设置吧!
Bahdisd 2013-11-09
  • 打赏
  • 举报
回复
应该是初始化的问题~
nabasasun 2013-11-08
  • 打赏
  • 举报
回复
引用 8 楼 lm_whales 的回复:
bmp=new Bitmap(width,height,PixelFormat32bppARGB); 数据还没有初始化,多半是全黑 只初始化了大小色彩模式,数据呢????????
源代码在一楼
lm_whales 2013-11-08
  • 打赏
  • 举报
回复
bmp=new Bitmap(width,height,PixelFormat32bppARGB); 数据还没有初始化,多半是全黑 只初始化了大小色彩模式,数据呢????????
真相重于对错 2013-11-01
  • 打赏
  • 举报
回复
可能取值时图像已经被回收了
许文君 2013-11-01
  • 打赏
  • 举报
回复
是取值的时候失败?
真相重于对错 2013-11-01
  • 打赏
  • 举报
回复
错误是什么?
nabasasun 2013-11-01
  • 打赏
  • 举报
回复
引用 6 楼 fengqinqdca 的回复:
你看看NEW成功了吗?
绝对成功了
华美乐章 2013-11-01
  • 打赏
  • 举报
回复
你看看NEW成功了吗?
加载更多回复(2)
A year and a half year ago, I published this article to the Codeguru site and got a number of requests about the Kriging algorithm contour map. Unfortunately, my project was changed shortly after that article and later I quit the company so I couldn‘t find time to finish this Contour business. A week ago, I happened to need a contour map again so I decided to solve the Kriging algorithm. I searched the Internet for a commercial library but they all look ugly and hard to use. So, I made up my mind to make my own algorithm. The Kriging algorithm is easy to find, but this algorithm needs a Matrix and solver (LU-Decomposition). Again, I couldn‘t find suitable code for this. I tried to use GSL first but this made my code too big and was slower. Finally, I went back to "Numerical Recipe in C"—yes, that horrible-looking C code—and changed the code there to my taste.If you read this article before, the rendering part hasn‘t been changed much. I added the Kriging algorithm and revised the codes a little bit. Following is the Kriging Algorithm:templatedouble GetDistance(const ForwardIterator start, int i, int j){ return ::sqrt(::pow(((*(start+i)).x - (*(start+j)).x), 2) + ::pow(((*(start+i)).y - (*(start+j)).y), 2));}templatedouble GetDistance(double xpos, double ypos, const ForwardIterator start, int i){ return ::sqrt(::pow(((*(start+i)).x - xpos), 2) + ::pow(((*(start+i)).y - ypos), 2));}templateclass TKriging : public TInterpolater{public: TKriging(const ForwardIterator first, const ForwardIterator last, double dSemivariance) : m_dSemivariance(dSemivariance) { m_nSize = 0; ForwardIterator start = first; while(start != last) { ++m_nSize; ++start; } m_matA.SetDimension(m_nSize, m_nSize); for(int j=0; j

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧