|
-
July 18th, 2005, 11:26 PM
#1
loading raw image in a frame
hello.. im currently working on some projects. I have this dialog box wherein i have a command button and a frame controls. if the button is clicked, u have to open the raw image and display it on the frame (IDC_DISPLAY).. can u please help me on how to do it..
-
July 19th, 2005, 01:57 AM
#2
Re: loading raw image in a frame
here use my function here:
Code:
// hwnd = handle to the image control
// W = width of the raw bits Image
// H = height of the raw bits Image
// lpBits = pointer to the raw bits image
// BitCount = 32,24 etc ( depend on the bit count ) defualt =32
void SetRawBitsToImage (HWND hwnd,int W,int H,BYTE *lpBits, int BitCount =32 )
{
HDC hDC = ::GetDC(hwnd);
::SetWindowPos(hwnd,0,0,0,W,H,SWP_NOMOVE);
BITMAPINFO bi;
memset(&bi,0,sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = W;
bi.bmiHeader.biHeight = H;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = BitCount;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = bi.bmiHeader.biWidth*bi.bmiHeader.biHeight*BitCount/8;
::SetDIBitsToDevice(hDC,
0,0,
W,
H,
0,
0,
0,bi.bmiHeader.biHeight,
lpBits,&bi,DIB_RGB_COLORS);
::ReleaseDC(hwnd,hDC);
}
now here is an example how you call it
Code:
HWND hImage = this->GetDlgItem(IDC_S)->GetSafeHwnd();
BYTE *Image = new BYTE[100*100*4]; // empty image
SetRawBitsToImage (hImage,100,100,Image ,32);
now in my sample i just created garbaged image and i display it, you should provide the real image, i dont know if you have the bitmap raw bits you can get them by ::GetBitmapBits(..) api.
and in order to load bitmap from disc use the ::LoadImage(..) api.
hope its covers what you need.
Cheers
Last edited by golanshahar; October 7th, 2005 at 01:55 AM.
-
December 20th, 2005, 10:05 AM
#3
Re: loading raw image in a frame
Could u pls explain more about what does this example do?
-
December 20th, 2005, 10:35 AM
#4
Re: loading raw image in a frame
 Originally Posted by rodolphe
Could u pls explain more about what does this example do?
why you are bumbing an old thread? 
this sample load bmp file from disc using the ::LoadImage(..) api.
then display the the raw bits using ::SetDIBitsToDevice(..).
Cheers
-
December 20th, 2005, 10:53 AM
#5
Re: loading raw image in a frame
After using the Loadimage and sure using a BITMAP variable (let's say bitmap), we know that bitmap.bmbits returns a Pointer to the location of the bit values for the bitmap. How would it possible to access to the memory content pointed by this pointer in order to read the "values" of the bitmap??
-
December 20th, 2005, 11:34 AM
#6
Re: loading raw image in a frame
 Originally Posted by rodolphe
After using the Loadimage and sure using a BITMAP variable (let's say bitmap), we know that bitmap.bmbits returns a Pointer to the location of the bit values for the bitmap. How would it possible to access to the memory content pointed by this pointer in order to read the "values" of the bitmap??
in this thread you created ( Device Context,DIB,DDB ) look at my first post there i gave you link to a thread LoadImage() which shows how load image from file and get the image raw bits.
Cheers
-
December 21st, 2005, 05:44 AM
#7
Re: loading raw image in a frame
golanshahar: thanks. I agree with you, but how do we simply read the content for the "bitmap.bmbits" pointer?
Note:
bmBits
Pointer to the location of the bit values for the bitmap. The bmBits member must be a long pointer to an array of character (1-byte) values.
Last edited by rodolphe; December 21st, 2005 at 06:54 AM.
-
December 21st, 2005, 08:25 AM
#8
Re: loading raw image in a frame
Add the follwing code with ur button click function
Code:
CString szFilename ("c:\\1.bmp");
HBITMAP hBmp = (HBITMAP)::LoadImage(
0,
szFilename,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION
);
CDC *pDC;
pDC=GetDC();
CBitmap bmpHello;
bmpHello.Attach(hBmp);
BITMAP bm;
bmpHello.GetObject( sizeof(BITMAP), &bm );
CDC dcMem;
dcMem.CreateCompatibleDC( pDC );
CBitmap* pbmpOld = dcMem.SelectObject( &bmpHello );
pDC->BitBlt( 30,50, bm.bmWidth, bm.bmHeight,&dcMem, 0,0, SRCCOPY );
dcMem.SelectObject( pbmpOld );
ReleaseDC( pDC );
If I Helped You, "Rate This Post"
Thanks
Guna
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|