How to display the Bitmap that created by CreateBitmap function?
-
how can i display the bitmap on ListView using CreateBitmap function?
void CThumbBmpView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CListView::OnPaint() for painting messages CRect r; GetClientRect(&r); // Paint to a memory device context to help // eliminate screen flicker. CXTPBufferDC memDC(dc, r); memDC.FillSolidRect(r, (RGB(255,255,255))); OnPrepareDC(&memDC); OnDraw(&memDC); } void CThumbBmpView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class HANDLE hFile; DWORD dwNumberOfBytesToRead; DWORD dwNumberOfBytesRead; hFile = CreateFile( "D:\\preview.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile == INVALID_HANDLE_VALUE ) { MessageBox( "Invalid Handle", "ERROR", MB_ICONERROR); } else { // MessageBox( "File Opened successfully"); BYTE *Buffer; DWORD p=SetFilePointer( hFile, 0x000, NULL, FILE_BEGIN ); Buffer = new BYTE [2363392+1]; BOOL bResult = ReadFile( hFile, Buffer, // nNumberOfBytesToRead, //specify the file size. 2363392, &dwNumberOfBytesRead, // NULL ); if(!bResult) MessageBox("Error"); //bmp.bmType =0; //bmp.bmWidth =32; //bmp.bmHeight =32; //bmp.bmWidthBytes=1024; //bmp.bmPlanes =2; //bmp.bmBitsPixel =32; //bmp.bmBits =Buffer; if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) MessageBox("cant Create Bitmap"); } CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) ) { return; } CBitmap* pOld = dcCompatible.SelectObject( &bitmap ); BITMAP bmInfo; if ( bitmap.GetObject( sizeof( bmInfo ), &bmInfo ) != 0 ) { pDC->BitBlt( 0,0, bmInfo.bmWidth, bmInfo.bmHeight, &dcCompatible, 0,0, SRCCOPY ); //pDC->StretchBlt(0,0,100,90,&dcCompatible,10,10,110,100, 32); } dcCompatible.SelectObject( pOld ); }
Regards, Srinivas
-
how can i display the bitmap on ListView using CreateBitmap function?
void CThumbBmpView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CListView::OnPaint() for painting messages CRect r; GetClientRect(&r); // Paint to a memory device context to help // eliminate screen flicker. CXTPBufferDC memDC(dc, r); memDC.FillSolidRect(r, (RGB(255,255,255))); OnPrepareDC(&memDC); OnDraw(&memDC); } void CThumbBmpView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class HANDLE hFile; DWORD dwNumberOfBytesToRead; DWORD dwNumberOfBytesRead; hFile = CreateFile( "D:\\preview.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile == INVALID_HANDLE_VALUE ) { MessageBox( "Invalid Handle", "ERROR", MB_ICONERROR); } else { // MessageBox( "File Opened successfully"); BYTE *Buffer; DWORD p=SetFilePointer( hFile, 0x000, NULL, FILE_BEGIN ); Buffer = new BYTE [2363392+1]; BOOL bResult = ReadFile( hFile, Buffer, // nNumberOfBytesToRead, //specify the file size. 2363392, &dwNumberOfBytesRead, // NULL ); if(!bResult) MessageBox("Error"); //bmp.bmType =0; //bmp.bmWidth =32; //bmp.bmHeight =32; //bmp.bmWidthBytes=1024; //bmp.bmPlanes =2; //bmp.bmBitsPixel =32; //bmp.bmBits =Buffer; if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) MessageBox("cant Create Bitmap"); } CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) ) { return; } CBitmap* pOld = dcCompatible.SelectObject( &bitmap ); BITMAP bmInfo; if ( bitmap.GetObject( sizeof( bmInfo ), &bmInfo ) != 0 ) { pDC->BitBlt( 0,0, bmInfo.bmWidth, bmInfo.bmHeight, &dcCompatible, 0,0, SRCCOPY ); //pDC->StretchBlt(0,0,100,90,&dcCompatible,10,10,110,100, 32); } dcCompatible.SelectObject( pOld ); }
Regards, Srinivas
vasu_sri wrote:
CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) )
this will not work. Yous should pass the pointer of original device context. it can be modified as follows
CClientDc dc(this) CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( &dc ) )
nave
-
how can i display the bitmap on ListView using CreateBitmap function?
void CThumbBmpView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CListView::OnPaint() for painting messages CRect r; GetClientRect(&r); // Paint to a memory device context to help // eliminate screen flicker. CXTPBufferDC memDC(dc, r); memDC.FillSolidRect(r, (RGB(255,255,255))); OnPrepareDC(&memDC); OnDraw(&memDC); } void CThumbBmpView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class HANDLE hFile; DWORD dwNumberOfBytesToRead; DWORD dwNumberOfBytesRead; hFile = CreateFile( "D:\\preview.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile == INVALID_HANDLE_VALUE ) { MessageBox( "Invalid Handle", "ERROR", MB_ICONERROR); } else { // MessageBox( "File Opened successfully"); BYTE *Buffer; DWORD p=SetFilePointer( hFile, 0x000, NULL, FILE_BEGIN ); Buffer = new BYTE [2363392+1]; BOOL bResult = ReadFile( hFile, Buffer, // nNumberOfBytesToRead, //specify the file size. 2363392, &dwNumberOfBytesRead, // NULL ); if(!bResult) MessageBox("Error"); //bmp.bmType =0; //bmp.bmWidth =32; //bmp.bmHeight =32; //bmp.bmWidthBytes=1024; //bmp.bmPlanes =2; //bmp.bmBitsPixel =32; //bmp.bmBits =Buffer; if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) MessageBox("cant Create Bitmap"); } CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) ) { return; } CBitmap* pOld = dcCompatible.SelectObject( &bitmap ); BITMAP bmInfo; if ( bitmap.GetObject( sizeof( bmInfo ), &bmInfo ) != 0 ) { pDC->BitBlt( 0,0, bmInfo.bmWidth, bmInfo.bmHeight, &dcCompatible, 0,0, SRCCOPY ); //pDC->StretchBlt(0,0,100,90,&dcCompatible,10,10,110,100, 32); } dcCompatible.SelectObject( pOld ); }
Regards, Srinivas
-
vasu_sri wrote:
CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) )
this will not work. Yous should pass the pointer of original device context. it can be modified as follows
CClientDc dc(this) CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( &dc ) )
nave
-
In addition to the above post, you must bitblit the content from memdc to dc in the CThumbBmpView::OnPaint()function after the statement OnDraw(&memDC);
nave
I agree only on this (see my reply above). Additionally, the OP have to first select the bitmap inside the memDC. To summarize, the OP has to: (1) Create a compatible (memory) DC (2) Select the bitmap inside the memory DC. (3) Preform Perform
BitBlt
from the MemDC to the actual one. Hope that helps :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
I agree only on this (see my reply above). Additionally, the OP have to first select the bitmap inside the memDC. To summarize, the OP has to: (1) Create a compatible (memory) DC (2) Select the bitmap inside the memory DC. (3) Preform Perform
BitBlt
from the MemDC to the actual one. Hope that helps :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
I don't think this is the problem. Actually I don't think it is a problem.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
CPallini wrote:
(1) Create a compatible (memory) DC (2) Select the bitmap inside the memory DC.
I think the CXTPBufferDC will be hadling this.
nave
-
And why? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
i did all what u asked me to do. i converted CDC to CClientDc. But still it doesn't work. i am doing this for the first time and so can u please explain me a little more clearly?? or can u give me any related link that can help me???
Regards, Srinivas
if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) The bitmap file not only contains the pixel data information. It also contain a file header. But the CreateBitmap funtion only need bufffer information. So you must remove the header information from the buffer before passing it to CreateBitmap function. But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.
nave
-
if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) The bitmap file not only contains the pixel data information. It also contain a file header. But the CreateBitmap funtion only need bufffer information. So you must remove the header information from the buffer before passing it to CreateBitmap function. But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.
nave
Naveen R wrote:
But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.
its because i don't have the File name or the file path with me. i just have the addresses of the starting sector and ending sector of the image file to work with. i am then reading the data between those sectors (which is nothing but the data of the image file) into a buffer. now i want to show the preview of that image by just using the data in the buffer before storing it as a file. i am still not able to succeed in what i am trying to do.
Regards, Srinivas
-
Naveen R wrote:
But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.
its because i don't have the File name or the file path with me. i just have the addresses of the starting sector and ending sector of the image file to work with. i am then reading the data between those sectors (which is nothing but the data of the image file) into a buffer. now i want to show the preview of that image by just using the data in the buffer before storing it as a file. i am still not able to succeed in what i am trying to do.
Regards, Srinivas