用插入资源的方式导入了一张位图。设置了菜单项,让位图显示到客户区。如何用菜单项读取每个点的的RGB值?void CRGB_YUVView::OnReadimg()
{
// TODO: Add your command handler code her
m_drawed=true;
CBitmap bt;
BITMAP b;
bt.LoadBitmap(IDB_BITMAP1);
bt.GetBitmap(&b);
CDC dc;
CDC *pDC=GetDC();
dc.CreateCompatibleDC(pDC);
dc.SelectObject(&bt);
pDC->BitBlt(0,0,800,600,&dc,0,0,SRCCOPY);
ReleaseDC(pDC);}//显示位图void CRGB_YUVView::OnRead_RGB_Value()
{
// TODO: Add your command handler code here
//依次读取BMP图像每个点的的RGB值,这里应该怎么写?求教,不知道改用哪个函数
}请高人指教一下~~~~万分感谢~~
{
// TODO: Add your command handler code her
m_drawed=true;
CBitmap bt;
BITMAP b;
bt.LoadBitmap(IDB_BITMAP1);
bt.GetBitmap(&b);
CDC dc;
CDC *pDC=GetDC();
dc.CreateCompatibleDC(pDC);
dc.SelectObject(&bt);
pDC->BitBlt(0,0,800,600,&dc,0,0,SRCCOPY);
ReleaseDC(pDC);}//显示位图void CRGB_YUVView::OnRead_RGB_Value()
{
// TODO: Add your command handler code here
//依次读取BMP图像每个点的的RGB值,这里应该怎么写?求教,不知道改用哪个函数
}请高人指教一下~~~~万分感谢~~
COLORREF GetPixel(POINT point) const;
BITMAP b;
bt.LoadBitmap(IDB_BITMAP1);
bt.GetBitmap(&b);
通过b计算位图的位数,长度等,然后分配一个空间,用bt.GetBitmapBits(...)取数据
{
// this function opens a bitmap file and loads the data into bitmapint file_handle, // the file handle
index; // looping indexUCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bit
OFSTRUCT file_data; // the file data information// open the file if it exists
if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
return(0);// now load the bitmap file header
_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));// test if this is a bitmap file
if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
{
// close the file
_lclose(file_handle); // return error
return(0);
} // end if// now we know this is a bitmap, so read in all the sections// first the bitmap infoheader// now load the bitmap file header
_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));// now load the color palette if there is one
if (bitmap->bitmapinfoheader.biBitCount == 8)
{
_lread(file_handle, &bitmap->palette,MAX_COLORS_PALETTE*sizeof(PALETTEENTRY)); // now set all the flags in the palette correctly and fix the reversed
// BGR RGBQUAD data format
for (index=0; index < MAX_COLORS_PALETTE; index++)
{
// reverse the red and green fields
int temp_color = bitmap->palette[index].peRed;
bitmap->palette[index].peRed = bitmap->palette[index].peBlue;
bitmap->palette[index].peBlue = temp_color;
// always set the flags word to this
bitmap->palette[index].peFlags = PC_NOCOLLAPSE;
} // end for index } // end if// finally the image data itself
_lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);// now read in the image, if the image is 8 or 16 bit then simply read it
// but if its 24 bit then read it into a temporary area and then convert
// it to a 16 bit imageif (bitmap->bitmapinfoheader.biBitCount==8 || bitmap->bitmapinfoheader.biBitCount==16 ||
bitmap->bitmapinfoheader.biBitCount==24)
{
// delete the last image if there was one
if (bitmap->buffer)
free(bitmap->buffer); // allocate the memory for the image
if (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
// close the file
_lclose(file_handle); // return error
return(0);
} // end if // now read it in
_lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage); } // end if
else
{
// serious problem
return(0); } // end else#if 0
// write the file info out
printf("\nfilename:%s \nsize=%d \nwidth=%d \nheight=%d \nbitsperpixel=%d \ncolors=%d \nimpcolors=%d",
filename,
bitmap->bitmapinfoheader.biSizeImage,
bitmap->bitmapinfoheader.biWidth,
bitmap->bitmapinfoheader.biHeight,
bitmap->bitmapinfoheader.biBitCount,
bitmap->bitmapinfoheader.biClrUsed,
bitmap->bitmapinfoheader.biClrImportant);
#endif// close the file
_lclose(file_handle);// flip the bitmap
Flip_Bitmap(bitmap->buffer,
bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8),
bitmap->bitmapinfoheader.biHeight);// return success
return(1);} // end Load_Bitmap_File///////////////////////////////////////////////////////////int Unload_Bitmap_File(BITMAP_FILE_PTR bitmap)
{
// this function releases all memory associated with "bitmap"
if (bitmap->buffer)
{
// release memory
free(bitmap->buffer); // reset pointer
bitmap->buffer = NULL; } // end if// return success
return(1);} // end Unload_Bitmap_File