PNG image in Dialog box
-
-
I have to diaplay one png image in dialog box(like bmp in picture control). any can help me... my image has some transparent things... if change it into bmp format than it won't be transparent so what i have to for diaplaying png image in dialog
-
I have to diaplay one png image in dialog box(like bmp in picture control). any can help me... my image has some transparent things... if change it into bmp format than it won't be transparent so what i have to for diaplaying png image in dialog
-
Create a 'picture control' to hold the picture
-
Derive a class from CStatic that'll draw the picture. It should declare a message map and handle WM_PAINT and use a CImage to hold the image. Note the call to
TransparentBlt
, which (as I've coded it) assumes that the top-;peft pixel of hte image is the transparent colour:class MyPic : public CStatic
{
public:
MyPic();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
private:
CImage image_;
};
MyPic::MyPic()
{
image_.Load(png filename);
}
void MyPic::OnPaint()
{
PAINTSTRUCT ps;
CDC * drawDC = BeginPaint(&ps);
CRect rcClient;
GetClientRect(&rcClient);
image_.TransparentBlt(*drawDC, rcClient, CRect(0, 0, image_.GetWidth(), image_.GetHeight()), image_.GetPixel(0, 0));
EndPaint(&ps);
} -
Declare a member variable wfor the picture control that is of the type you've just made.
-
See your picture be displayed!
-
-
-
Create a 'picture control' to hold the picture
-
Derive a class from CStatic that'll draw the picture. It should declare a message map and handle WM_PAINT and use a CImage to hold the image. Note the call to
TransparentBlt
, which (as I've coded it) assumes that the top-;peft pixel of hte image is the transparent colour:class MyPic : public CStatic
{
public:
MyPic();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
private:
CImage image_;
};
MyPic::MyPic()
{
image_.Load(png filename);
}
void MyPic::OnPaint()
{
PAINTSTRUCT ps;
CDC * drawDC = BeginPaint(&ps);
CRect rcClient;
GetClientRect(&rcClient);
image_.TransparentBlt(*drawDC, rcClient, CRect(0, 0, image_.GetWidth(), image_.GetHeight()), image_.GetPixel(0, 0));
EndPaint(&ps);
} -
Declare a member variable wfor the picture control that is of the type you've just made.
-
See your picture be displayed!
-
-
I already tried this using following code but that image lost it's transparency and looks like bmp HBITMAP m_bitmap = NULL; CxImage image("myfile.png", CXIMAGE_FORMAT_PNG); ... CDC* hdc = m_picture.GetDC(); HBITMAP m_bitmap = image.MakeBitmap(hdc->m_hDC); HBITMAP hOldBmp = m_picture.SetBitmap(m_bitmap); if (hOldBmp) DeleteObject(hOldBmp); if (hdc->m_hDC) m_picture.ReleaseDC(hdc); ... if (m_bitmap) DeleteObject(m_bitmap);
-
ganesh.dp wrote:
Cimage is in VC6.0?
Probably not - but you didn't say you were using 10-11 year old software.
CImage
is definitely in VS.NET 2003 - and that's the oldest VS I have. -
ganesh.dp wrote:
Cimage is in VC6.0?
Probably not - but you didn't say you were using 10-11 year old software.
CImage
is definitely in VS.NET 2003 - and that's the oldest VS I have. -
I already tried this using following code but that image lost it's transparency and looks like bmp HBITMAP m_bitmap = NULL; CxImage image("myfile.png", CXIMAGE_FORMAT_PNG); ... CDC* hdc = m_picture.GetDC(); HBITMAP m_bitmap = image.MakeBitmap(hdc->m_hDC); HBITMAP hOldBmp = m_picture.SetBitmap(m_bitmap); if (hOldBmp) DeleteObject(hOldBmp); if (hdc->m_hDC) m_picture.ReleaseDC(hdc); ... if (m_bitmap) DeleteObject(m_bitmap);
Ah, you won't get transparent blitting from the picture control (which is a CStatic actually), look at Stuart Dootson's post. You will have to do the blitting yourself, i recommend using CxImage's own blitting methods.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
CImage
is just a wrapper around a GDI+Image
[^] - you could try using GDI+ - you will need to get a version of the Platform that a) is compatible with VS6, and b) contains GDI+. As this Platform SDK[^] is the last one that works with VS6, I guess it's your best option.