Drawimage
-
I am trying to draw image using bitblt method. When I try to
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);it works and image is getting drawn but when I use
Bitmap *bitmap = Bitmap::FromFile(L"d:\\Projects\\res\\state.bmp");
It does not draw any image... Pleas help to sort out the problem. I need to draw image directly from path, not from resource and using bitblt only..
-
I am trying to draw image using bitblt method. When I try to
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);it works and image is getting drawn but when I use
Bitmap *bitmap = Bitmap::FromFile(L"d:\\Projects\\res\\state.bmp");
It does not draw any image... Pleas help to sort out the problem. I need to draw image directly from path, not from resource and using bitblt only..
I coded like this for my application.
CString bmpFilePath;
HBITMAP hBmp;
hBmp = (HBITMAP)::LoadImage(NULL,bmpFilePath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
CDC dcImage;
if(!dcImage.CreateCompatibleDC(pDC))
return;
BITMAP bm;
CBitmap* pOldBitmap;
bmp.GetBitmap(&bm);
pOldBitmap = dcImage.SelectObject(&bmp);
pDC->BitBlt(350,100, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
dcImage.SelectObject(pOldBitmap);Anu
-
I coded like this for my application.
CString bmpFilePath;
HBITMAP hBmp;
hBmp = (HBITMAP)::LoadImage(NULL,bmpFilePath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
CDC dcImage;
if(!dcImage.CreateCompatibleDC(pDC))
return;
BITMAP bm;
CBitmap* pOldBitmap;
bmp.GetBitmap(&bm);
pOldBitmap = dcImage.SelectObject(&bmp);
pDC->BitBlt(350,100, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
dcImage.SelectObject(pOldBitmap);Anu
-
I coded like this for my application.
CString bmpFilePath;
HBITMAP hBmp;
hBmp = (HBITMAP)::LoadImage(NULL,bmpFilePath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
CDC dcImage;
if(!dcImage.CreateCompatibleDC(pDC))
return;
BITMAP bm;
CBitmap* pOldBitmap;
bmp.GetBitmap(&bm);
pOldBitmap = dcImage.SelectObject(&bmp);
pDC->BitBlt(350,100, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
dcImage.SelectObject(pOldBitmap);Anu
-
I am trying to draw image using bitblt method. When I try to
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);it works and image is getting drawn but when I use
Bitmap *bitmap = Bitmap::FromFile(L"d:\\Projects\\res\\state.bmp");
It does not draw any image... Pleas help to sort out the problem. I need to draw image directly from path, not from resource and using bitblt only..
You've not shown the code that actually draws the image, but I'll take a guess at the problem. In your first code snippet, it is a CBitmap instance that will be used for drawing. In your second snippet, it is a pointer to a Bitmap instance that is used. Your drawing code will need to be adjusted accordingly. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
I use this code
// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
HBITMAP result=NULL;Gdiplus::Bitmap\* bitmap = new Gdiplus::Bitmap(szFilename,false); bitmap->GetHBITMAP(NULL, &result); delete bitmap; return result;
}
Note: You have to startup and shutdown the GDI+ system. I usually do this in apps initialization and destruction (winmain or main if not mfc apps)
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);hInst = hInstance; InitCommonControls(); // The user interface is a modal dialog box DialogBox(hInstance, MAKEINTRESOURCE(DLG\_MAIN), NULL, (DLGPROC)DialogProc); Gdiplus::GdiplusShutdown(gdiplusToken);
}
-
You've not shown the code that actually draws the image, but I'll take a guess at the problem. In your first code snippet, it is a CBitmap instance that will be used for drawing. In your second snippet, it is a pointer to a Bitmap instance that is used. Your drawing code will need to be adjusted accordingly. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
:), basically my motive is to draw image (png/jpg) using bitblt...I will adjust code accordingly.
-
See this link.It may help you. http://stackoverflow.com/questions/2490661/how-to-load-png-jpeg-images-using-mfc[^]
Anu
-
I am trying to draw image using bitblt method. When I try to
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);it works and image is getting drawn but when I use
Bitmap *bitmap = Bitmap::FromFile(L"d:\\Projects\\res\\state.bmp");
It does not draw any image... Pleas help to sort out the problem. I need to draw image directly from path, not from resource and using bitblt only..
-
MFC by default support only BMP file, however you can take services of different library that suits your need, one of them is gdiplus, search Google for more information
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You