因为一维数组里面放的的width*height 的8bit灰度图像数据,我想把它与一个Bitmap 对象相关联,这样的话,就可以用GDI+中的Graphics 等对象和函数 来方便将imageArray中的数据在窗口中显示出来,(我知道用opencv等第三方库也可以做,但我想使用GDI+来做)!    
哪位大侠能帮帮忙,告诉我怎么实现这一功能吗?  急急急! 注:可以将其封装在函数void creatBitmapFormArray(Bitmap bitmap, BYTE* imageArray, int width, int height) 

解决方案 »

  1.   

    Bitmap::SetPixel(x, y, color)
    The SetPixel method sets the color of a specified pixel in this bitmap.Status SetPixel(
      INT x,
      INT y,
      const Color& color
    );
    Parameters

    [in] Integer that specifies the x-coordinate (column) of the pixel. 

    [in] Integer that specifies the y-coordinate (row) of the pixel. 
    color 
    [in] Reference to a Color object that specifies the color to set. 
      

  2.   

    这是设置图像中的每一个像素啊, 但我想从一个单独的数组 出发,来创建一个Bitmap对象,这样的话,可以用像你上面述说的setPixel等方法来方便对数组的处理。因为很重要的一点是:一维数组(或二维数组也行) 这种图像原始的灰度值 存储方式 ,我是很需要的,因为很多8bit 灰度图像的算法的实现都是基于BYTE型的一维数组的!..
      

  3.   

    你把BYTE数据转换成对应的32位颜色值不就行了
      

  4.   

    问题不在于32位还是8位啊!下面是我写的实现函数,集成后是可以运行的,但是显示的图像被截掉了一部分,初步怀疑是长宽的设置问题,但看看代码和msdn,又没啥问题啊!!
    纠结死了!
    高人快现身啊!
    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;
    }
      

  5.   

    问题不在于32位还是8位啊!下面是我写的实现函数,集成后是可以运行的,但是显示的图像被截掉了一部分,初步怀疑是长宽的设置问题,但看看代码和msdn,又没啥问题啊!!
    纠结死了!
    高人快现身啊!
    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;
    }
      

  6.   

    有人告诉我用createbitmap???