This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Image Composer > July 2005 > AlphaBlend CImage





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author AlphaBlend CImage
Janiv Ratson

2005-07-11, 4:31 am

Hello, I want to draw a bitmap using CImage.
I use the AlphaBlend CImage method to do it.
The problem is that I do not get the result as I want it.
The image is drawn fine but the alpha blending is not "exactly" as the
background.
So the "transparent" area of the image is shown as almost as the background
color and not as exactly (as I want it to be).
i.e. if my background color is red, the image transparent area is colored
with pink or something, it is always a brighter color than the background
(background green->transparent area light green, etc).

The function as I use it is :
m_imgDefault.AlphaBlend(dc,rc.left,rc.top,255,AC_SRC_OVER);

Also, every other application (Microsoft's) succeed on showing the
transparent area, so the problem is not with the image, but with my code.

Please Help,

Thanks,

Janiv Ratson.


Michael Phillips, Jr.

2005-07-12, 7:23 pm

m_imgDefault.AlphaBlend(dc,rc.left,rc.top,your alpha,AC_SRC_OVER);

If you use the default 0xFF(255) for the alpha,
then your image will be drawn with per pixel
alpha blending as below:

Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red
Dst.Green = Src.Green + (1 - Src.Alpha) * Dst.Green
Dst.Blue = Src.Blue + (1 - Src.Alpha) * Dst.Blue
Dest.Alpha = Src.Alpha + (1-SrcAlpha) *Dst.Alpha

If you don't use the default, then the formula is as follows:
Dst.Red = Src.Red*(your alpha/255.0) + Dst.Red * (1.0 - (your alpha/255.0))
Dst.Green = Src.Green*(your alpha/255.0) + Dst.Green * (1.0 - (your
alpha/255.0))
Dst.Blue = Src.Blue*(your alpha/255.0) + Dst.Blue * (1.0 - (your
alpha/255.0))
Dst.Alpha = Src.Alpha*(your alpha/255.0) + Dst.Alpha * (1.0 - (your
alpha/255.0))

"Janiv Ratson" <janiv@aoe6.net> wrote in message
news:eb5cB6dhFHA.3316@TK2MSFTNGP14.phx.gbl...
> Hello, I want to draw a bitmap using CImage.
> I use the AlphaBlend CImage method to do it.
> The problem is that I do not get the result as I want it.
> The image is drawn fine but the alpha blending is not "exactly" as the
> background.
> So the "transparent" area of the image is shown as almost as the
> background
> color and not as exactly (as I want it to be).
> i.e. if my background color is red, the image transparent area is colored
> with pink or something, it is always a brighter color than the background
> (background green->transparent area light green, etc).
>
> The function as I use it is :
> m_imgDefault.AlphaBlend(dc,rc.left,rc.top,255,AC_SRC_OVER);
>
> Also, every other application (Microsoft's) succeed on showing the
> transparent area, so the problem is not with the image, but with my code.
>
> Please Help,
>
> Thanks,
>
> Janiv Ratson.
>
>



Janiv Ratson

2005-07-13, 4:20 am

Thanks,
That's exactly what I do. I use the default alpha (0xFF). it does not work
for me.
Why?

"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:%23HS38rxhFHA.1232@TK2MSFTNGP15.phx.gbl...
> m_imgDefault.AlphaBlend(dc,rc.left,rc.top,your alpha,AC_SRC_OVER);
>
> If you use the default 0xFF(255) for the alpha,
> then your image will be drawn with per pixel
> alpha blending as below:
>
> Dst.Red = Src.Red + (1 - Src.Alpha) * Dst.Red
> Dst.Green = Src.Green + (1 - Src.Alpha) * Dst.Green
> Dst.Blue = Src.Blue + (1 - Src.Alpha) * Dst.Blue
> Dest.Alpha = Src.Alpha + (1-SrcAlpha) *Dst.Alpha
>
> If you don't use the default, then the formula is as follows:
> Dst.Red = Src.Red*(your alpha/255.0) + Dst.Red * (1.0 - (your

alpha/255.0))
> Dst.Green = Src.Green*(your alpha/255.0) + Dst.Green * (1.0 - (your
> alpha/255.0))
> Dst.Blue = Src.Blue*(your alpha/255.0) + Dst.Blue * (1.0 - (your
> alpha/255.0))
> Dst.Alpha = Src.Alpha*(your alpha/255.0) + Dst.Alpha * (1.0 - (your
> alpha/255.0))
>
> "Janiv Ratson" <janiv@aoe6.net> wrote in message
> news:eb5cB6dhFHA.3316@TK2MSFTNGP14.phx.gbl...
colored[color=darkred]
background[color=darkred]
code.[color=darkred]
>
>



Michael Phillips, Jr.

2005-07-13, 7:17 pm

By using an alpha of 255, you will draw against an opaque
background. The transparent areas of your source bitmap
will not blend with the background!

If you choose any other alpha, your background will blend
with the transparent areas of your source bitmap according
to the formula in my last post.


"Janiv Ratson" <janiv@aoe6.net> wrote in message
news:eb4fTr3hFHA.576@TK2MSFTNGP15.phx.gbl...
> Thanks,
> That's exactly what I do. I use the default alpha (0xFF). it does not work
> for me.
> Why?
>
> "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
> news:%23HS38rxhFHA.1232@TK2MSFTNGP15.phx.gbl...
> alpha/255.0))
> colored
> background
> code.
>
>



Janiv Ratson

2005-07-14, 7:18 am

Thanks Michael.
I do not understand your formula,
but how do I use it ?
Thanks and sorry,
Janiv Ratson.


"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:uzpe1$6hFHA.968@TK2MSFTNGP10.phx.gbl...
> By using an alpha of 255, you will draw against an opaque
> background. The transparent areas of your source bitmap
> will not blend with the background!
>
> If you choose any other alpha, your background will blend
> with the transparent areas of your source bitmap according
> to the formula in my last post.
>
>
> "Janiv Ratson" <janiv@aoe6.net> wrote in message
> news:eb4fTr3hFHA.576@TK2MSFTNGP15.phx.gbl...
work[color=darkred]
the[color=darkred]
>
>



Michael Phillips, Jr.

2005-07-14, 7:17 pm

The function AlphaBlend(dc,rc.left,rc.top,your alpha,AC_SRC_OVER),
draws your source image over a background.

If your source image has transparent pixels, then those pixels will be
blended
with the background. If your image consisted of a painting of the "Mona
Lisa",
and the alpha channel was blue surrounding the picture frame, then the
transparent areas (blue) would be replaced with the background that
your draw against because of the blending process.

If your alpha channel contains more than one color, then the blending
against the background color will cause color shifts due to the formulas
that are used to blend the image.

By changing the alpha value that you pass into the function, you change
the degree of blending against the background ( e.g., 0x01(1%) very little
blending,
0x128(50%) blending, 0xFF full blending(100%) ).

Choose different background colors to see how your image looks.
Try a simple background of black or white. Check your image's alpha
channel to see if more that one color is used for the transparent areas.
If so, try to correct so that the transparent areas have the same color
( e.g., green or whatever you want ).


"Janiv Ratson" <janiv@aoe6.net> wrote in message
news:%23GmdbvFiFHA.2424@TK2MSFTNGP09.phx.gbl...
> Thanks Michael.
> I do not understand your formula,
> but how do I use it ?
> Thanks and sorry,
> Janiv Ratson.
>
>
> "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
> news:uzpe1$6hFHA.968@TK2MSFTNGP10.phx.gbl...
> work
> the
>
>



Janiv Ratson

2005-07-17, 7:14 am

If I understand you correctly, you suggest that I must know the alpha blend
color(s).
But the images that I use in my application are dynamic, a user may create
its own images, or import images from wherever he wants.
I will never be able to know the number of colors or the color itself of the
alpha blend.
I need a very generic solution.
Microsoft do it in its CFileDialog control, every image that is shown in
this dialog that has transparent, looks great (on thumbnails view). Also
when I run another application (an MFC application that shows XUL files
[MFCEmbedded.exe]) that shows my screens, the images look transparent for
any image I put on the screen (imported, own created, etc.).
Sorry to bother you, but I need a solution, ASAP.
I really appreciate your kind help.
Thanks in advanced,
Janiv Ratson.


"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:uc1A4ZIiFHA.1948@TK2MSFTNGP12.phx.gbl...
> The function AlphaBlend(dc,rc.left,rc.top,your alpha,AC_SRC_OVER),
> draws your source image over a background.
>
> If your source image has transparent pixels, then those pixels will be
> blended
> with the background. If your image consisted of a painting of the "Mona
> Lisa",
> and the alpha channel was blue surrounding the picture frame, then the
> transparent areas (blue) would be replaced with the background that
> your draw against because of the blending process.
>
> If your alpha channel contains more than one color, then the blending
> against the background color will cause color shifts due to the formulas
> that are used to blend the image.
>
> By changing the alpha value that you pass into the function, you change
> the degree of blending against the background ( e.g., 0x01(1%) very little
> blending,
> 0x128(50%) blending, 0xFF full blending(100%) ).
>
> Choose different background colors to see how your image looks.
> Try a simple background of black or white. Check your image's alpha
> channel to see if more that one color is used for the transparent areas.
> If so, try to correct so that the transparent areas have the same color
> ( e.g., green or whatever you want ).
>
>
> "Janiv Ratson" <janiv@aoe6.net> wrote in message
> news:%23GmdbvFiFHA.2424@TK2MSFTNGP09.phx.gbl...
message[color=darkred]
my[color=darkred]
>
>



Michael Phillips, Jr.

2005-07-17, 7:16 pm

Per the documentation, the constant alpha is combined with the source alpha.

The behavior that you see is by design.

The following example demonstrates this fact:

http://msdn.microsoft.com/library/d...itmaps_2b00.asp

Microsoft uses the gdiplus API to display the thumbnails in the file dialog
box.

You have more flexibility in displaying your images. It supports SRC_OVER
and SRC_COPY
for transparent bitmaps.

Try both methods ( GDI-AlphaBlend Function, GDI+ Graphics DrawImage
Function)
and see which ot the two methods provides the result that you desire.


"Janiv Ratson" <janiv@aoe6.net> wrote in message
news:ukHQIfqiFHA.3288@TK2MSFTNGP09.phx.gbl...
> If I understand you correctly, you suggest that I must know the alpha
> blend
> color(s).
> But the images that I use in my application are dynamic, a user may create
> its own images, or import images from wherever he wants.
> I will never be able to know the number of colors or the color itself of
> the
> alpha blend.
> I need a very generic solution.
> Microsoft do it in its CFileDialog control, every image that is shown in
> this dialog that has transparent, looks great (on thumbnails view). Also
> when I run another application (an MFC application that shows XUL files
> [MFCEmbedded.exe]) that shows my screens, the images look transparent for
> any image I put on the screen (imported, own created, etc.).
> Sorry to bother you, but I need a solution, ASAP.
> I really appreciate your kind help.
> Thanks in advanced,
> Janiv Ratson.
>
>
> "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
> news:uc1A4ZIiFHA.1948@TK2MSFTNGP12.phx.gbl...
> message
> my
>
>



Michael Phillips, Jr.

2005-07-17, 7:16 pm

In order to help you out, I have written the following test case
that demonstrates your problem and gives you the solution:

1) The test images came from here:
http://www.schaik.com/pngsuite/pngsuite.html
2) The window color on my desktop was blue ( COLOR_BACKGROUND )

#define STRICT
#define UNICODE
#define _UNICODE
#define WINVER 0x0500
#include <windows.h>
#include <windowsx.h>
#include <ole2.h>
#include <commctrl.h>
#include <shlwapi.h>
#include <shlobj.h>
#include <shellapi.h>
#include <atlimage.h>

#pragma comment( lib, "gdi32.lib" )
#pragma comment( lib, "kernel32.lib" )
#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "shlwapi.lib" )
#pragma comment( lib, "ole32.lib" )
#pragma comment( lib, "shell32.lib" )
#pragma comment( lib, "comctl32.lib" )
#pragma comment( lib, "msimg32.lib" )

HINSTANCE g_hinst;

CImage img;
Gdiplus::Image *img2;

class Window
{
public:
HWND GetHWND() { return m_hwnd; }
protected:
virtual LRESULT HandleMessage(
UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual void PaintContent(PAINTSTRUCT *pps)
{
img.AlphaBlend(pps->hdc, 0, 0 );
Gdiplus::Graphics graphics(pps->hdc);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQuality);
graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver);
graphics.DrawImage(img2, 0, 100, img2->GetWidth(), img2->GetHeight());
}
virtual LPCTSTR ClassName() = 0;
virtual BOOL WinRegisterClass(WNDCLASS *pwc)
{ return RegisterClass(pwc); }
virtual ~Window() { }

HWND WinCreateWindow(DWORD dwExStyle, LPCTSTR pszName,
DWORD dwStyle, int x, int y, int cx, int cy,
HWND hwndParent, HMENU hmenu)
{
Register();
return CreateWindowEx(dwExStyle, ClassName(), pszName, dwStyle,
x, y, cx, cy, hwndParent, hmenu, g_hinst, this);
}
private:
void Register();
void OnPaint();
void OnPrintClient(HDC hdc);
static LRESULT CALLBACK s_WndProc(HWND hwnd,
UINT uMsg, WPARAM wParam, LPARAM lParam);
protected:
HWND m_hwnd;
};

void Window::Register()
{
WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = Window::s_WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hinst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetSysColorBrush(COLOR_BACKGROUND);
wc.lpszMenuName = NULL;
wc.lpszClassName = ClassName();

WinRegisterClass(&wc);
}

LRESULT CALLBACK Window::s_WndProc(
HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
Window *self;
if (uMsg == WM_NCCREATE) {
LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
self = reinterpret_cast<Window *>(lpcs->lpCreateParams);
self->m_hwnd = hwnd;
SetWindowLongPtr(hwnd, GWLP_USERDATA,
reinterpret_cast<LPARAM>(self));
} else {
self = reinterpret_cast<Window *>
(GetWindowLongPtr(hwnd, GWLP_USERDATA));
}
if (self) {
return self->HandleMessage(uMsg, wParam, lParam);
} else {
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}

LRESULT Window::HandleMessage(
UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lres;

switch (uMsg) {
case WM_NCDESTROY:
lres = DefWindowProc(m_hwnd, uMsg, wParam, lParam);
SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
delete this;
return lres;

case WM_PAINT:
OnPaint();
return 0;

case WM_PRINTCLIENT:
OnPrintClient(reinterpret_cast<HDC>(wParam));
return 0;
}

return DefWindowProc(m_hwnd, uMsg, wParam, lParam);
}

void Window::OnPaint()
{
PAINTSTRUCT ps;
BeginPaint(m_hwnd, &ps);
PaintContent(&ps);
EndPaint(m_hwnd, &ps);
}

void Window::OnPrintClient(HDC hdc)
{
PAINTSTRUCT ps;
ps.hdc = hdc;
GetClientRect(m_hwnd, &ps.rcPaint);
PaintContent(&ps);
}

class RootWindow : public Window
{
public:
virtual LPCTSTR ClassName() { return TEXT("AlphaBlend"); }
static RootWindow *Create();
protected:
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT OnCreate();
private:
HWND m_hwndChild;
};

LRESULT RootWindow::OnCreate()
{
img.Load(TEXT("C:\\Temp\\PngSuite\\TP1N3P08.PNG"));
img2 = Gdiplus::Image::FromFile(TEXT("C:\\Temp\\PngSuite\\TBWN3P08.PNG"),
FALSE);

return 0;
}

LRESULT RootWindow::HandleMessage(
UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_CREATE:
return OnCreate();

case WM_DESTROY:
if ( img2 )
delete img2;
return 0;

case WM_NCDESTROY:
// Death of the root window ends the thread
PostQuitMessage(0);
break;

case WM_SIZE:
if (m_hwndChild) {
SetWindowPos(m_hwndChild, NULL, 0, 0,
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
SWP_NOZORDER | SWP_NOACTIVATE);
}
return 0;

case WM_SETFOCUS:
if (m_hwndChild) {
SetFocus(m_hwndChild);
}
return 0;
}

return __super::HandleMessage(uMsg, wParam, lParam);
}

RootWindow *RootWindow::Create()
{
RootWindow *self = new RootWindow();
if (self && self->WinCreateWindow(0,
TEXT("AlphaBlend"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL)) {
return self;
}
delete self;
return NULL;
}

int PASCAL
WinMain(HINSTANCE hinst, HINSTANCE, LPSTR, int nShowCmd)
{
g_hinst = hinst;

if (SUCCEEDED(CoInitialize(NULL))) {
InitCommonControls();

RootWindow *prw = RootWindow::Create();
if (prw) {
ShowWindow(prw->GetHWND(), nShowCmd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
CoUninitialize();
}
return 0;
}


"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:%23vc7%23RuiFHA.2152@TK2MSFTNGP14.phx.gbl...
> Per the documentation, the constant alpha is combined with the source
> alpha.
>
> The behavior that you see is by design.
>
> The following example demonstrates this fact:
>
> http://msdn.microsoft.com/library/d...itmaps_2b00.asp
>
> Microsoft uses the gdiplus API to display the thumbnails in the file
> dialog box.
>
> You have more flexibility in displaying your images. It supports SRC_OVER
> and SRC_COPY
> for transparent bitmaps.
>
> Try both methods ( GDI-AlphaBlend Function, GDI+ Graphics DrawImage
> Function)
> and see which ot the two methods provides the result that you desire.
>
>
> "Janiv Ratson" <janiv@aoe6.net> wrote in message
> news:ukHQIfqiFHA.3288@TK2MSFTNGP09.phx.gbl...
>
>



Janiv Ratson

2005-07-18, 4:19 am

Hello Michael,

It works!!!
I can't tell you how much I thank you, I really appreciate your very kind
help.
Thanks a lot for your patience.

One more last small question:
For CImage there is a IsNull method to check whether an image is null or
not, is there something similar in GDI Plus image? I need to check the image
and if it is valid (or not null), I want to delete it (before I create
another image).
Thanks in advanced.
Janiv Ratson.


"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:OIvRDpviFHA.3468@TK2MSFTNGP10.phx.gbl...
> In order to help you out, I have written the following test case
> that demonstrates your problem and gives you the solution:
>
> 1) The test images came from here:
> http://www.schaik.com/pngsuite/pngsuite.html
> 2) The window color on my desktop was blue ( COLOR_BACKGROUND )
>
> #define STRICT
> #define UNICODE
> #define _UNICODE
> #define WINVER 0x0500
> #include <windows.h>
> #include <windowsx.h>
> #include <ole2.h>
> #include <commctrl.h>
> #include <shlwapi.h>
> #include <shlobj.h>
> #include <shellapi.h>
> #include <atlimage.h>
>
> #pragma comment( lib, "gdi32.lib" )
> #pragma comment( lib, "kernel32.lib" )
> #pragma comment( lib, "user32.lib" )
> #pragma comment( lib, "shlwapi.lib" )
> #pragma comment( lib, "ole32.lib" )
> #pragma comment( lib, "shell32.lib" )
> #pragma comment( lib, "comctl32.lib" )
> #pragma comment( lib, "msimg32.lib" )
>
> HINSTANCE g_hinst;
>
> CImage img;
> Gdiplus::Image *img2;
>
> class Window
> {
> public:
> HWND GetHWND() { return m_hwnd; }
> protected:
> virtual LRESULT HandleMessage(
> UINT uMsg, WPARAM wParam, LPARAM lParam);
> virtual void PaintContent(PAINTSTRUCT *pps)
> {
> img.AlphaBlend(pps->hdc, 0, 0 );
> Gdiplus::Graphics graphics(pps->hdc);
> graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQuality);
> graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
> graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver);
> graphics.DrawImage(img2, 0, 100, img2->GetWidth(), img2->GetHeight());
> }
> virtual LPCTSTR ClassName() = 0;
> virtual BOOL WinRegisterClass(WNDCLASS *pwc)
> { return RegisterClass(pwc); }
> virtual ~Window() { }
>
> HWND WinCreateWindow(DWORD dwExStyle, LPCTSTR pszName,
> DWORD dwStyle, int x, int y, int cx, int cy,
> HWND hwndParent, HMENU hmenu)
> {
> Register();
> return CreateWindowEx(dwExStyle, ClassName(), pszName, dwStyle,
> x, y, cx, cy, hwndParent, hmenu, g_hinst, this);
> }
> private:
> void Register();
> void OnPaint();
> void OnPrintClient(HDC hdc);
> static LRESULT CALLBACK s_WndProc(HWND hwnd,
> UINT uMsg, WPARAM wParam, LPARAM lParam);
> protected:
> HWND m_hwnd;
> };
>
> void Window::Register()
> {
> WNDCLASS wc;
> wc.style = 0;
> wc.lpfnWndProc = Window::s_WndProc;
> wc.cbClsExtra = 0;
> wc.cbWndExtra = 0;
> wc.hInstance = g_hinst;
> wc.hIcon = NULL;
> wc.hCursor = LoadCursor(NULL, IDC_ARROW);
> wc.hbrBackground = GetSysColorBrush(COLOR_BACKGROUND);
> wc.lpszMenuName = NULL;
> wc.lpszClassName = ClassName();
>
> WinRegisterClass(&wc);
> }
>
> LRESULT CALLBACK Window::s_WndProc(
> HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
> {
> Window *self;
> if (uMsg == WM_NCCREATE) {
> LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
> self = reinterpret_cast<Window *>(lpcs->lpCreateParams);
> self->m_hwnd = hwnd;
> SetWindowLongPtr(hwnd, GWLP_USERDATA,
> reinterpret_cast<LPARAM>(self));
> } else {
> self = reinterpret_cast<Window *>
> (GetWindowLongPtr(hwnd, GWLP_USERDATA));
> }
> if (self) {
> return self->HandleMessage(uMsg, wParam, lParam);
> } else {
> return DefWindowProc(hwnd, uMsg, wParam, lParam);
> }
> }
>
> LRESULT Window::HandleMessage(
> UINT uMsg, WPARAM wParam, LPARAM lParam)
> {
> LRESULT lres;
>
> switch (uMsg) {
> case WM_NCDESTROY:
> lres = DefWindowProc(m_hwnd, uMsg, wParam, lParam);
> SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
> delete this;
> return lres;
>
> case WM_PAINT:
> OnPaint();
> return 0;
>
> case WM_PRINTCLIENT:
> OnPrintClient(reinterpret_cast<HDC>(wParam));
> return 0;
> }
>
> return DefWindowProc(m_hwnd, uMsg, wParam, lParam);
> }
>
> void Window::OnPaint()
> {
> PAINTSTRUCT ps;
> BeginPaint(m_hwnd, &ps);
> PaintContent(&ps);
> EndPaint(m_hwnd, &ps);
> }
>
> void Window::OnPrintClient(HDC hdc)
> {
> PAINTSTRUCT ps;
> ps.hdc = hdc;
> GetClientRect(m_hwnd, &ps.rcPaint);
> PaintContent(&ps);
> }
>
> class RootWindow : public Window
> {
> public:
> virtual LPCTSTR ClassName() { return TEXT("AlphaBlend"); }
> static RootWindow *Create();
> protected:
> LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
> LRESULT OnCreate();
> private:
> HWND m_hwndChild;
> };
>
> LRESULT RootWindow::OnCreate()
> {
> img.Load(TEXT("C:\\Temp\\PngSuite\\TP1N3P08.PNG"));
> img2 = Gdiplus::Image::FromFile(TEXT("C:\\Temp\\PngSuite\\TBWN3P08.PNG"),
> FALSE);
>
> return 0;
> }
>
> LRESULT RootWindow::HandleMessage(
> UINT uMsg, WPARAM wParam, LPARAM lParam)
> {
> switch (uMsg) {
> case WM_CREATE:
> return OnCreate();
>
> case WM_DESTROY:
> if ( img2 )
> delete img2;
> return 0;
>
> case WM_NCDESTROY:
> // Death of the root window ends the thread
> PostQuitMessage(0);
> break;
>
> case WM_SIZE:
> if (m_hwndChild) {
> SetWindowPos(m_hwndChild, NULL, 0, 0,
> GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
> SWP_NOZORDER | SWP_NOACTIVATE);
> }
> return 0;
>
> case WM_SETFOCUS:
> if (m_hwndChild) {
> SetFocus(m_hwndChild);
> }
> return 0;
> }
>
> return __super::HandleMessage(uMsg, wParam, lParam);
> }
>
> RootWindow *RootWindow::Create()
> {
> RootWindow *self = new RootWindow();
> if (self && self->WinCreateWindow(0,
> TEXT("AlphaBlend"), WS_OVERLAPPEDWINDOW,
> CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
> NULL, NULL)) {
> return self;
> }
> delete self;
> return NULL;
> }
>
> int PASCAL
> WinMain(HINSTANCE hinst, HINSTANCE, LPSTR, int nShowCmd)
> {
> g_hinst = hinst;
>
> if (SUCCEEDED(CoInitialize(NULL))) {
> InitCommonControls();
>
> RootWindow *prw = RootWindow::Create();
> if (prw) {
> ShowWindow(prw->GetHWND(), nShowCmd);
> MSG msg;
> while (GetMessage(&msg, NULL, 0, 0)) {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
> }
> CoUninitialize();
> }
> return 0;
> }
>
>
> "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
> news:%23vc7%23RuiFHA.2152@TK2MSFTNGP14.phx.gbl...
http://msdn.microsoft.com/library/d...itmaps_2b00.asp[color=darkred]
SRC_OVER[color=darkred]
of[color=darkred]
in[color=darkred]
Also[color=darkred]
for[color=darkred]
"Mona[color=darkred]
formulas[color=darkred]
change[color=darkred]
areas.[color=darkred]
color[color=darkred]
message[color=darkred]
alpha,AC_SRC_OVER);[color=darkred]
"exactly"[color=darkred]
the[color=darkred]
with[color=darkred]
>
>



Michael Phillips, Jr.

2005-07-18, 7:18 pm

The Gdiplus API returns errors as a "Status" variable.

You can check the error for image creation as follows:

Gdiplus::Image *pImage = Gdiplus::Image::FromFile(TEXT("Image.png"));
Status stat = pImage->GetLastStatus();

In addition to errors defined in the Gdiplus API, errors may be returned
as a "Win32Error". If you get that error, you call the System's
::GetLastError()
function to obtain the System defined error.



"Janiv Ratson" <janiv@aoe6.net> wrote in message
news:Ojq89k2iFHA.2180@TK2MSFTNGP15.phx.gbl...
> Hello Michael,
>
> It works!!!
> I can't tell you how much I thank you, I really appreciate your very kind
> help.
> Thanks a lot for your patience.
>
> One more last small question:
> For CImage there is a IsNull method to check whether an image is null or
> not, is there something similar in GDI Plus image? I need to check the
> image
> and if it is valid (or not null), I want to delete it (before I create
> another image).
> Thanks in advanced.
> Janiv Ratson.
>
>
> "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
> news:OIvRDpviFHA.3468@TK2MSFTNGP10.phx.gbl...
> http://msdn.microsoft.com/library/d...itmaps_2b00.asp
> SRC_OVER
> of
> in
> Also
> for
> "Mona
> formulas
> change
> areas.
> color
> message
> alpha,AC_SRC_OVER);
> "exactly"
> the
> with
>
>



Janiv Ratson

2005-07-18, 7:18 pm

Thanks, I cannot use GetLastStatus, cause it sometimes return NULL to
pImage.
I'll use GetLastError.
Thanks a lot, again,
Janiv Ratson.

"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
news:OFHxGy5iFHA.1048@tk2msftngp13.phx.gbl...
> The Gdiplus API returns errors as a "Status" variable.
>
> You can check the error for image creation as follows:
>
> Gdiplus::Image *pImage = Gdiplus::Image::FromFile(TEXT("Image.png"));
> Status stat = pImage->GetLastStatus();
>
> In addition to errors defined in the Gdiplus API, errors may be returned
> as a "Win32Error". If you get that error, you call the System's
> ::GetLastError()
> function to obtain the System defined error.
>
>
>
> "Janiv Ratson" <janiv@aoe6.net> wrote in message
> news:Ojq89k2iFHA.2180@TK2MSFTNGP15.phx.gbl...
kind[color=darkred]
graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);[color=darkred]
http://msdn.microsoft.com/library/d...itmaps_2b00.asp[color=darkred]
alpha[color=darkred]
itself[color=darkred]
shown[color=darkred]
transparent[color=darkred]
message[color=darkred]
blending[color=darkred]
alpha[color=darkred]
as[color=darkred]
>
>



Michael Phillips, Jr.

2005-07-18, 7:18 pm

enum Gdiplus::Status Ok = 0

If GetLastStatus returns 0 or Ok then the image
was created without error.

The Gdiplus API does not support the full
specification for many images.

It will not load all .png test images, .tiff, .ico, etc.

You may have to use 3rd party libraries or write your
own encoders/decoders to supplement what Gdiplus
supports.




"Janiv Ratson" <janiv@aoe6.net> wrote in message
news:epCx4B6iFHA.1412@TK2MSFTNGP09.phx.gbl...
> Thanks, I cannot use GetLastStatus, cause it sometimes return NULL to
> pImage.
> I'll use GetLastError.
> Thanks a lot, again,
> Janiv Ratson.
>
> "Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message
> news:OFHxGy5iFHA.1048@tk2msftngp13.phx.gbl...
> kind
> graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
> http://msdn.microsoft.com/library/d...itmaps_2b00.asp
> alpha
> itself
> shown
> transparent
> message
> blending
> alpha
> as
>
>



Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews