16,372
社区成员




void main()
{
if(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0))
{
cout<<1<<endl;
}
CBitmap bitmap;
// load bitmap
CBitmap Bitmap;
Bitmap.LoadBitmapW(103);
BITMAP bmp;
Bitmap.GetBitmap(&bmp);
cout<<"宽度"<<bmp.bmWidth<<endl;
cout<<"高度"<<bmp.bmHeight<<endl;
cout<<"颜色位数"<<bmp.bmBitsPixel<<endl;
cout<<"bmBits"<<bmp.bmBits<<endl;
cout<<"一行像素所占的字节数"<<bmp.bmWidthBytes<<endl;
cout<<"调色板颜色数"<<bmp.bmPlanes<<endl;
cout<<"类型"<<bmp.bmType<<endl;
CDC memDC;
CBitmap *pOldBitmap;
HDC hDC = ::GetDC(NULL); //用参数NULL表示获取屏幕DC的句柄
CDC *pDC = CDC::FromHandle(hDC);
memDC.CreateCompatibleDC(pDC);
pOldBitmap = memDC.SelectObject(&Bitmap);
int x=23;
int y=5;
COLORREF clr = memDC.GetPixel(x, y);
BYTE R = GetRValue(clr);
BYTE G = GetGValue(clr);
BYTE B = GetBValue(clr);
cout<<R<<endl;
BITMAPINFOHEADER bih = {0};//位图信息头,所有域初始化为0
//Specifies the number of bits required to indicate the color of a pixel.
bih.biBitCount = bmp.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biHeight = bmp.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight ;
bih.biWidth = bmp.bmWidth;
char * p = new char[400];
p[1]=12;
//HBITMAP h_bmp=(HBITMAP)::SelectObject(NULL,(HBITMAP)Bitmap);
HBITMAP h_bmp = (HBITMAP)Bitmap;
GetDIBits(memDC.m_hDC,h_bmp, 0, bmp.bmHeight, p,(LPBITMAPINFO)&bih, DIB_RGB_COLORS);
int i = (bmp.bmHeight - y - 1) * bmp.bmWidthBytes + x * 32;
R = p[i+2];
G = p[i+1];
B = p[i];
}
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "afxwin.h"
void main()
{
CBitmap bitmap;
// load bitmap
CBitmap Bitmap;
HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL,_T("task4.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
Bitmap.Attach(hBitmap);
BITMAP bmp;
Bitmap.GetBitmap(&bmp);
CDC memDC;
CBitmap *pOldBitmap;
HDC hDC = ::GetDC(NULL); //用参数NULL表示获取屏幕DC的句柄
CDC *pDC = CDC::FromHandle(hDC);
memDC.CreateCompatibleDC(pDC);
pOldBitmap = memDC.SelectObject(&Bitmap);
int x=0;
int y=0;
COLORREF clr = memDC.GetPixel(x, y);
BYTE R = GetRValue(clr);
BYTE G = GetGValue(clr);
BYTE B = GetBValue(clr);
BITMAPINFOHEADER bih = {0};//位图信息头,所有域初始化为0
//Specifies the number of bits required to indicate the color of a pixel.
bih.biBitCount = bmp.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biHeight = bmp.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight ;
bih.biWidth = bmp.bmWidth;
char * p = new char[400];
p[1]=12;
//HBITMAP h_bmp=(HBITMAP)::SelectObject(NULL,(HBITMAP)Bitmap);
HBITMAP h_bmp = (HBITMAP)Bitmap;
GetDIBits(memDC.m_hDC,h_bmp, 0, bmp.bmHeight, p,(LPBITMAPINFO)&bih, DIB_RGB_COLORS);
int i = (bmp.bmHeight - y - 1) * bmp.bmWidthBytes + x * 32;
R = p[i+2];
G = p[i+1];
B = p[i];
}
我这里可以啊 ···