因为一维数组里面放的的width*height 的8bit灰度图像数据,我想把它与一个Bitmap 对象相关联,这样的话,就可以用GDI+中的Graphics 等对象和函数 来方便将imageArray中的数据在窗口中显示出来,(我知道用opencv等第三方库也可以做,但我想使用GDI+来做)!
哪位大侠能帮帮忙,告诉我怎么实现这一功能吗? 急急急! 注:可以将其封装在函数void creatBitmapFormArray(Bitmap bitmap, BYTE* imageArray, int width, int height)
哪位大侠能帮帮忙,告诉我怎么实现这一功能吗? 急急急! 注:可以将其封装在函数void creatBitmapFormArray(Bitmap bitmap, BYTE* imageArray, int width, int height)
The SetPixel method sets the color of a specified pixel in this bitmap.Status SetPixel(
INT x,
INT y,
const Color& color
);
Parameters
x
[in] Integer that specifies the x-coordinate (column) of the pixel.
y
[in] Integer that specifies the y-coordinate (row) of the pixel.
color
[in] Reference to a Color object that specifies the color to set.
纠结死了!
高人快现身啊!
bool CImageProcessingDoc::createBitmapFromArray( BYTE* array, Bitmap*& bitmap, int height, int width )
{
BYTE* imageData = new BYTE[width * height * 4];
BYTE* p = imageData;
for (int i = 0; i < width * height; i++)
{
memset(p, array[i], 3);
memset(p+3, 255, 1);
p+=4;
}
Bitmap tempBitmap(width, height, width * 4, PixelFormat32bppARGB, imageData);
bitmap = &tempBitmap;
return true;
}
纠结死了!
高人快现身啊!
bool CImageProcessingDoc::createBitmapFromArray( BYTE* array, Bitmap*& bitmap, int height, int width )
{
BYTE* imageData = new BYTE[width * height * 4];//用来存放32位的数据,因为Bitmap的构造函数是要求32位数据的!
BYTE* p = imageData;
for (int i = 0; i < width * height; i++)
{
memset(p, array[i], 3);//RGB三通道都设置相同的值,即将任何图像都设置为灰度图
memset(p+3, 255, 1);//alpha 通道设置为不透明
p+=4;//四个字节代表一个像素点的值
}
//由array 构造Bitmap,
Bitmap tempBitmap(width, height, width * 4, PixelFormat32bppARGB, imageData);
//!!!!关键就是构造后,当显示图像(在ondraw()中用Graphics.show())时,尺寸上与原始图像不符,被截掉了一部分!!!
bitmap = &tempBitmap;
return true;
}