View previous topic :: View next topic |
Author |
Message |
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Fri Dec 31, 2004 3:04 pm Post subject: Loading images |
|
|
Is it possible to load an image in a control, say, a panel? The source could either be a file or a resource (or maybe even a stream). If not, I'd like that. |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Mon Jan 03, 2005 1:04 am Post subject: Re: Loading images |
|
|
Carlos wrote: | Is it possible to load an image in a control, say, a panel? | No, but you can do it yourself by attaching a paint handler and using the BitBlt() GDI function. Windows API LoadImageA() can be used to load up the image. PictureBox control and loading and blitting images will be added to DFL some time, but I don't think there will ever be an image property on controls as seen in other GUI libraries. Here's a snippet you can use: Code: | extern(Windows)
{
enum: UINT
{
LR_LOADFROMFILE = 0x0010,
}
BOOL BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop);
}
const int FOO_WIDTH = 50;
const int FOO_HEIGHT = 50;
HBITMAP hbm;
hbm = LoadImageA(null, "foo.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if(!hbm)
throw new Exception("Unable to load image.");
myForm.paint ~= &myForm_paint;
void myForm_paint(Object sender, PaintEventArgs ea)
{
HDC memdc;
HGDIOBJ hgo;
memdc = CreateCompatibleDC(ea.graphics.handle);
hgo = SelectObject(memdc, hbm);
BitBlt(ea.graphics.handle, 0, 0, FOO_WIDTH, FOO_HEIGHT, memdc, 0, 0, SRCCOPY);
SelectObject(memdc, hgo); // Old bitmap.
DeleteDC(memdc);
} |
|
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Tue Jan 04, 2005 8:32 pm Post subject: Re: Loading images |
|
|
Vathix wrote: | Carlos wrote: | Is it possible to load an image in a control, say, a panel? | No, but you can do it yourself by attaching a paint handler and using the BitBlt() GDI function. Windows API LoadImageA() can be used to load up the image. PictureBox control and loading and blitting images will be added to DFL some time, but I don't think there will ever be an image property on controls as seen in other GUI libraries. Here's a snippet you can use: Code: | extern(Windows)
{
enum: UINT
{
LR_LOADFROMFILE = 0x0010,
}
BOOL BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop);
}
const int FOO_WIDTH = 50;
const int FOO_HEIGHT = 50;
HBITMAP hbm;
hbm = LoadImageA(null, "foo.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if(!hbm)
throw new Exception("Unable to load image.");
myForm.paint ~= &myForm_paint;
void myForm_paint(Object sender, PaintEventArgs ea)
{
HDC memdc;
HGDIOBJ hgo;
memdc = CreateCompatibleDC(ea.graphics.handle);
hgo = SelectObject(memdc, hbm);
BitBlt(ea.graphics.handle, 0, 0, FOO_WIDTH, FOO_HEIGHT, memdc, 0, 0, SRCCOPY);
SelectObject(memdc, hgo); // Old bitmap.
DeleteDC(memdc);
} |
|
Ok. Thanks. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|