Thread: Re: [Dev-C++] display bitmap
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2003-06-20 10:48:19
|
Have you run this program and not had an error yet? Because I think you are
deleting a DC but you've not called DeleteObject(), so the memory is still
being used.
Try a shut down and reboot, and chang ethe code before trying again.
>From: "Vlada Djurovic" <dj...@im...>
>To: "'DevC++ help'" <dev...@li...>
>Subject: [Dev-C++] display bitmap
>Date: Fri, 20 Jun 2003 12:27:55 +0200
>
>Hi.
>In this piece of code, I try to load bitmap image from a file and display
>it
>in a window. When I run the program, nothing happens. After the call to
>LoadImage(), I call the error() function, which calls GetLastError() and
>displays a message box with error description. In this way, I receive a
>message "Not enough storage is available to process this command". Now, I'm
>not sure if there something wrong with the code, or I realy run out of
>memory (which I doubt). My computer is Pentium 2 with 128 MB RAM and 20GB
>hard drive. This code is actually the only code in this program, except for
>standard Windows code, so I don't think there should be any memory leak.
>Can
>you tell me if the code is OK?
>P.S. I should also say that there's no message "Could not load image", so I
>guess the bitmap handle is valid?
>How can that be if LoadImage() could not be completed?
>---------------------
> LPTSTR szFileName=TEXT("bitmapa.bmp");
> HBITMAP
>hBitmap=(HBITMAP)LoadImage(GetModuleHandle(NULL),szFileName,IMAGE_BITMAP,0,0
>,
> LR_LOADFROMFILE|LR_CREATEDIBSECTION);
> error(); //this function calls GetLastError() and displays
>a
>message box
> if(!hBitmap)
> MessageBox(hwnd,"Could not load image","Error",MB_OK);
> BITMAP bmp;
> GetObject(hBitmap,sizeof(BITMAP),&bmp);
> PAINTSTRUCT ps;
> HDC hDC=BeginPaint(hwnd,&ps);
> HDC memDC=CreateCompatibleDC(hDC);
> SelectObject(memDC,hBitmap);
> BitBlt(hDC,0,0,bmp.bmWidth,bmp.bmHeight,memDC,0,0,SRCCOPY);
> DeleteDC(memDC);
> EndPaint(hwnd,&ps);
>-------------------------------------
>------------
>Vlada
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: INetU
>Attention Web Developers & Consultants: Become An INetU Hosting Partner.
>Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
>INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger
|
|
From: Daniel G. <sp...@ho...> - 2003-06-20 12:06:10
|
If the bitmap couldn't be found though the error message would say so wouldn't it? There's another GetLastError() call I think called GetLastErrorEx() or something (look on MSDN.com), maybe that will give more details? Glad to hear the code works on someone's machine anyway! Maybe the bitmap is too difficult to read? Is it a simple image? Krzysztof what colour depth was your bitmap, maybe the code fails if it is 24-bit or above perhaps? That matters a lot I hear with bitmaps. >From: Krzysztof 'Saveman' Kapuscik <sa...@ze...> >Reply-To: Krzysztof Kapuscik <sa...@op...> >To: dev...@li... >Subject: Re: [Dev-C++] display bitmap >Date: Fri, 20 Jun 2003 13:48:18 +0200 > >Hello Vlada, > >Friday, June 20, 2003, 12:27:55 PM, you wrote: > >VD> Hi. >VD> In this piece of code, I try to load bitmap image from a file and >display it >VD> in a window. When I run the program, nothing happens. After the call to >VD> LoadImage(), I call the error() function, which calls GetLastError() >and >VD> displays a message box with error description. In this way, I receive a >VD> message "Not enough storage is available to process this command". Now, >I'm >VD> not sure if there something wrong with the code, or I realy run out of >VD> memory (which I doubt). My computer is Pentium 2 with 128 MB RAM and >20GB >VD> hard drive. This code is actually the only code in this program, except >for >VD> standard Windows code, so I don't think there should be any memory >leak. Can >VD> you tell me if the code is OK? >VD> P.S. I should also say that there's no message "Could not load image", >so I >VD> guess the bitmap handle is valid? >VD> How can that be if LoadImage() could not be completed? >VD> ------------------------------------- >VD> ------------ >VD> Vlada > >I don't know what's wrong with you code, because it works on my machine :) > >But I changed it a bit - look there: >(i putted it into WindowProcedure) > > HBITMAP hBitmap; > LPTSTR szFileName = TEXT("bitmapa.bmp"); > BITMAP bmp; > HBITMAP hOldBMP; > PAINTSTRUCT ps; > HDC hDC; > HDC memDC; > > switch (message) /* handle the messages */ > { > case WM_PAINT: > hBitmap =(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, > IMAGE_BITMAP, 0, 0, >LR_LOADFROMFILE|LR_CREATEDIBSECTION); > if(hBitmap) > { > GetObject(hBitmap, sizeof(BITMAP), &bmp); > hDC = BeginPaint(hwnd, &ps); > memDC = CreateCompatibleDC(hDC); > hOldBMP = (HBITMAP)SelectObject(memDC, hBitmap); > BitBlt(hDC, 0, 0, bmp.bmWidth, bmp.bmHeight, memDC, 0, 0, >SRCCOPY); > SelectObject(memDC, hOldBMP); > DeleteDC(memDC); > EndPaint(hwnd, &ps); > DeleteObject(hBitmap); > } > else > { > // you could get additional info about error here > // using GetLastError() > MessageBox(hwnd, "Could not load image", "Error", MB_OK); > } > break; > case WM_DESTROY: > PostQuitMessage (0); /* send a WM_QUIT to the message >queue */ > break; > default: /* for messages that we don't deal >with */ > return DefWindowProc (hwnd, message, wParam, lParam); > } > > >Check if your "bitmapa.bmp" file is inside default program directory... > >-- >Best regards, > Krzysztof > >mailto:sa...@op... >http://www.saveman.w.pl > > > > >------------------------------------------------------- >This SF.Net email is sponsored by: INetU >Attention Web Developers & Consultants: Become An INetU Hosting Partner. >Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! >INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile |
|
From: Krzysztof K. <sa...@op...> - 2003-06-20 12:26:55
|
Hello Daniel, Friday, June 20, 2003, 2:06:04 PM, you wrote: DG> If the bitmap couldn't be found though the error message would say so DG> wouldn't it? DG> There's another GetLastError() call I think called GetLastErrorEx() or DG> something (look on MSDN.com), maybe that will give more details? DG> Glad to hear the code works on someone's machine anyway! DG> Maybe the bitmap is too difficult to read? Is it a simple image? DG> Krzysztof what colour depth was your bitmap, maybe the code fails if it is DG> 24-bit or above perhaps? That matters a lot I hear with bitmaps. The bitmap params was: 144 x 15 x 16 colors I checked it also with bigger image: 1024 x 768 x 24bits (colors = 16.7 mln) With both of them program works without errors. A small hiny: LoadImage have problems with loading compressed bitmaps... I don't know why, my friend told me this and i trust him, because he is writting Windows apps for a long time. (Compressed bitmaps use RLE encoding scheme (Run Length Encoding)). He use: OleInitialize and OleLoadPicturePath I have his code how to do this but it is written in assembler... -- Best regards, Krzysztof mailto:sa...@op... http://www.saveman.w.pl |
|
From: Graeme F. <gr...@dr...> - 2003-06-20 17:46:27
|
A couple of points BeginPaint() should only be used in the WM_PAINT because the paint message is triggered by an invalid region and so BeginPaint only allows you to paint in the invalid region - it also validates the invalid region for you. You should be able to check this by looking at the rcPaint field returned in the PaintStructure - that is a RECT of the invalid region. Secondly you can also try the LoadBitmap function to load a bitmap from a file mentioned in a resource file. Slightly easier than loadImage. Graeme. |
|
From: Vlada D. <dj...@im...> - 2003-06-20 11:16:58
|
----- Original Message -----
From: "Daniel Glenfield" <sp...@ho...>
To: <dj...@im...>; <dev...@li...>
Sent: Friday, June 20, 2003 12:48 PM
Subject: Re: [Dev-C++] display bitmap
> Have you run this program and not had an error yet? Because I think you
are
> deleting a DC but you've not called DeleteObject(), so the memory is still
> being used.
>
> Try a shut down and reboot, and chang ethe code before trying again.
>
This happens since the first time I ran the program. Anyway, I did a reboot,
and changed the code:
HBITMAP hOldBMP=(HBITMAP)SelectObject(memDC,hBitmap);
BitBlt(.......);
SelectObject(memDC,hOldBMP);
DeleteDC(memDC);
but still same thing. I think that even with a memory leak, it sholud run at
least a few times, asuming there's nothing wrong with the code. Maybe I
shold try it on some other machine?
>
> >From: "Vlada Djurovic" <dj...@im...>
> >To: "'DevC++ help'" <dev...@li...>
> >Subject: [Dev-C++] display bitmap
> >Date: Fri, 20 Jun 2003 12:27:55 +0200
> >
> >Hi.
> >In this piece of code, I try to load bitmap image from a file and display
> >it
> >in a window. When I run the program, nothing happens. After the call to
> >LoadImage(), I call the error() function, which calls GetLastError() and
> >displays a message box with error description. In this way, I receive a
> >message "Not enough storage is available to process this command". Now,
I'm
> >not sure if there something wrong with the code, or I realy run out of
> >memory (which I doubt). My computer is Pentium 2 with 128 MB RAM and 20GB
> >hard drive. This code is actually the only code in this program, except
for
> >standard Windows code, so I don't think there should be any memory leak.
> >Can
> >you tell me if the code is OK?
> >P.S. I should also say that there's no message "Could not load image", so
I
> >guess the bitmap handle is valid?
> >How can that be if LoadImage() could not be completed?
> >---------------------
> > LPTSTR szFileName=TEXT("bitmapa.bmp");
> > HBITMAP
>
>hBitmap=(HBITMAP)LoadImage(GetModuleHandle(NULL),szFileName,IMAGE_BITMAP,0,
0
> >,
> > LR_LOADFROMFILE|LR_CREATEDIBSECTION);
> > error(); //this function calls GetLastError() and
displays
> >a
> >message box
> > if(!hBitmap)
> > MessageBox(hwnd,"Could not load image","Error",MB_OK);
> > BITMAP bmp;
> > GetObject(hBitmap,sizeof(BITMAP),&bmp);
> > PAINTSTRUCT ps;
> > HDC hDC=BeginPaint(hwnd,&ps);
> > HDC memDC=CreateCompatibleDC(hDC);
> > SelectObject(memDC,hBitmap);
> >
BitBlt(hDC,0,0,bmp.bmWidth,bmp.bmHeight,memDC,0,0,SRCCOPY);
> > DeleteDC(memDC);
> > EndPaint(hwnd,&ps);
> >-------------------------------------
> >------------
> >Vlada
> >
> >
> >
> >-------------------------------------------------------
> >This SF.Net email is sponsored by: INetU
> >Attention Web Developers & Consultants: Become An INetU Hosting Partner.
> >Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
> >INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
> >_______________________________________________
> >Dev-cpp-users mailing list
> >Dev...@li...
> >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
> _________________________________________________________________
> Stay in touch with absent friends - get MSN Messenger
> http://www.msn.co.uk/messenger
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: INetU
> Attention Web Developers & Consultants: Become An INetU Hosting Partner.
> Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
> INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|