数组转换为Gdiplus::Bitmap
来源:互联网 发布:小米手机抢购软件 编辑:程序博客网 时间:2024/06/16 01:39
首先在某一个位置初始化对应的数组:
BOOL CCPUJuliaSetDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
…………..
//为对话框添加关闭按钮
LONG lStyle= GetWindowLong(this->m_hWnd, GWL_STYLE);
lStyle |=WS_SYSMENU;
SetWindowLong(this->m_hWnd,GWL_STYLE, lStyle);
CRect rc;
GetClientRect(&rc);
// m_ImageDim是成员变量,类型是int
m_ImageDim= min(rc.Width(), rc.Height());
//生成对应的数组,m_pBuffer是成员变量
m_pBuffer = new BYTE[m_ImageDim *m_ImageDim * 4];
for(int y =0; y < m_ImageDim; ++y){
for(intx = 0; x < m_ImageDim; ++x){
m_pBuffer[y* m_ImageDim*4 + x*4] = 0;//Blue
m_pBuffer[y* m_ImageDim*4 + x*4 + 1] = 0;//Green
m_pBuffer[y* m_ImageDim*4 + x*4 + 2] = 255 * CalculateJuliaSet(x, y);//Red
m_pBuffer[y* m_ImageDim*4 + x*4 + 3] = 255;//Alpha
}
}
returnTRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
然后在OnPaint函数中利用Gdiplus::Bitmap的一个构造函数:
Bitmap(INT width, INT height, INT stride, PixelFormatformat, BYTE *scan0);
注意:在MSDN的解释中,stride也就是一幅图像一行的byte的数量(也就是图像宽度×每一像素的位平面数)必须是4的整数倍,我试了一下,如果不使用四通道,而采用3或者1通道,图像不会显示出来(很奇怪!!!)。下面的代码使用了Gdiplus,为了使Gdiplus生效,必须在构造函数中调用GdiplusStartup,在析构函数中GdiplusShutdown。
在OnPaint函数中的代码:
void CCPUJuliaSetDlg::OnPaint()
{
if(IsIconic())
{
CPaintDCdc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()),0);
// 使图标在工作区矩形中居中
intcxIcon = GetSystemMetrics(SM_CXICON);
intcyIcon = GetSystemMetrics(SM_CYICON);
CRectrect;
GetClientRect(&rect);
intx = (rect.Width() - cxIcon + 1) / 2;
inty = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x,y, m_hIcon);
}
else
{
//CDialogEx::OnPaint();
CPaintDCdc(this);
Graphicsg(dc.GetSafeHdc());
//BitmapmemBitmap(m_ImageDim, m_ImageDim, 1*m_ImageDim,
//PixelFormat8bppIndexed,m_pBuffer);
//BitmapmemBitmap(m_ImageDim, m_ImageDim, 3*m_ImageDim,
//PixelFormat24bppRGB, m_pBuffer);
BitmapmemBitmap(m_ImageDim, m_ImageDim, 4*m_ImageDim,
PixelFormat32bppARGB,m_pBuffer);
g.DrawImage(&memBitmap,0.0f, 0.0f, 0.0f, 0.0f,
(float)m_ImageDim, (float)m_ImageDim,UnitPixel);
}
}
- 数组转换为Gdiplus::Bitmap
- CImage转换Gdiplus::Bitmap
- Gdiplus byte *数据转换为Bitmap类型图片
- 通过BYTE数组创建Gdiplus::Bitmap
- gdiplus Bitmap 转 gdi BITMAP
- 如何将YUV的byte数组转换为bitmap
- vc++ 加了加入GDIPlus.lib链接库问题,无法从“Gdiplus::Rect *”转换为“const Gdiplus::Rect”
- *Bitmap 转换为 *Image
- Bitmap转换为Drawable
- View转换为Bitmap
- View转换为Bitmap
- View转换为bitmap
- Activity之间传递Bitmap,将Bitmap转换为Byte数组后传递
- OpenCV中IplImage 与 Gdiplus 中Bitmap之间的相互转换
- OpenCV中IplImage 与 Gdiplus 中Bitmap之间的相互转换
- 图片资源类型转换为bitmap
- 抓取mc为bitmap数组
- gdiplus图片格式转换
- UML ,类的关系解析
- POJ 2897 Dramatic Multiplications(简单模拟)
- InflateException: Binary XML file line #20: Error inflating class fragment
- 树链剖分+树状数组
- epoll源码分析---sys_epoll_wait()函数 http://blog.csdn.net/hbhhww/article/details/7746638
- 数组转换为Gdiplus::Bitmap
- spring-xmemcached 集成
- TCP协议发送SKB时ip_summed成员的设置 http://blog.csdn.net/justlinux2010/article/details/8508455
- Java标签的使用
- iOS讲解迷惑深入浅出之block那点事
- java代码实现JDBC连接MySql以及引用驱动程序包
- 第三周 项目4-顺序表的应用2
- 经典算法题——第十二题 线段树
- HDU 1015 爆搜 /dfs+回溯