A very easy question, can you help me please

lovelyxinxin_1983 2008-02-11 09:27:31

Sorry for my English, but I have no Chinese IME here.

The problem is how can I show a picture according to a predefined data array?

For example.

short[] pixeldata = {0, 255,
0 255};

height = 2;
width = 2;


then I have a 2*2 picture, which looks like

black white
black white

Thank you



...全文
138 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovelyxinxin_1983 2008-02-23
  • 打赏
  • 举报
回复
谢谢大家的回复,尤其是ringphone
ringphone 2008-02-14
  • 打赏
  • 举报
回复
CreateCompatibleBitmap,然后把数据SetDIBBits
如果不想创建BMP而直接显示,用DrawDibDraw,但是必须自己填充BITMAPINFO和BITMAOINFOHEADER结构,告诉系统图象大小颜色等信息
Yao-debo 2008-02-11
  • 打赏
  • 举报
回复
如果是这样的话,你需要根据BMP的文件格式一点点填充内存;
lovelyxinxin_1983 2008-02-11
  • 打赏
  • 举报
回复
Thank you for your replies

I wonder if I can copy the source array directly to the target array,
for example

I get the array as
char[] data = {0,0,0,255,255,255,0,0,0,255,255,255};

And I just copy the source data to the target memory space. If this is possible or not?

Thank you
oldmanzhao 2008-02-11
  • 打赏
  • 举报
回复
把颜色转换成COLORREF比如0就是RGB(0,0,0),255就是(255,255,255),然后根据长宽做个循环,用SetPixel输出:
for (int i =0;i<height;i++)
for (int j=0;j<width;j++)
pDC->SetPixel(j,i, RGB(pixeldata[j][i],pixeldata[j][i],pixeldata[j][i]));
cnzdgs 2008-02-11
  • 打赏
  • 举报
回复
StretchDIBits

15,978

社区成员

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

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