|
|
Comments and Discussions
|
|
 |
|

|
see MSDN samples (SDK + KB + doc) for alpha - blending with GDI+ or GDI.
10 x better...
|
|
|
|

|
Is it possible to draw on that image ? say a rectangle ?
What is the way to access the pixel buffer and modify it ? rgba-wise
Would it take a double buffer for the drawing to avoid the flickering ?
tx
|
|
|
|

|
Hi, I am trying to write code in clear WinAPI, but I am doing some mistake (probably I wasn't able to understand the MFC code):
#ifndef WINVER
# define WINVER 0x0502
#endif
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0502
#endif
#ifndef _WIN32_WINDOWS
# define _WIN32_WINDOWS 0x0410
#endif
#ifndef _WIN32_IE
# define _WIN32_IE 0x0600
#endif
#include <windows.h>
#include "path_to_CxImage_library/ximage.h"
#define MAIN_CLASS_NAME L"AlphaBlendingWindowClass"
HWND mainWindow;
CxImage image;
LRESULT CALLBACK WindowProcMain(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch ( uMsg )
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
image.Draw(hdc, 0, 0, 200, 200, NULL, true);
EndPaint(hwnd, &ps);
} break;
case WM_LBUTTONDOWN:
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void Update() {
POINT position = {100,100};
SIZE size = {200, 200};
POINT src = {0, 0};
HDC screenDC = GetDC(NULL);
HDC memDC = CreateCompatibleDC(NULL);
UINT32 *data = new UINT32[size.cx*size.cy];
ZeroMemory(data, sizeof(UINT32)*size.cx*size.cy);
HBITMAP newBitmap = CreateBitmap(size.cx, size.cy, 1, 32, data);
HBITMAP oldBitmap = (HBITMAP)SelectObject(memDC, newBitmap);
image.Draw(memDC, 0, 0, 200, 200, NULL, true);
BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
if (!UpdateLayeredWindow(mainWindow, screenDC, &position, &size, memDC, &src, 0, &bf, ULW_ALPHA)) {
MessageBox(NULL, L"Window wasn't updated!", L"Error", MB_OK | MB_ICONERROR);
}
delete[] data;
SelectObject(memDC, oldBitmap);
DeleteObject(newBitmap);
DeleteDC(memDC);
ReleaseDC(NULL, screenDC);
}
BOOL InitApp(HINSTANCE instance) {
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = instance;
wc.lpfnWndProc = WindowProcMain;
wc.lpszClassName = MAIN_CLASS_NAME;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if ( !RegisterClassEx(&wc) )
return FALSE;
mainWindow = CreateWindowEx(WS_EX_LAYERED, MAIN_CLASS_NAME, L"AlphaBlendedWindow",
WS_VISIBLE | WS_POPUP, 100, 100, 200, 200, NULL, NULL, instance, NULL);
if ( mainWindow == NULL ) {
MessageBox(NULL, L"Cannot create window!", L"Error", MB_OK | MB_ICONERROR);
return FALSE;
}
if (!image.Load(L"../debug/image.png")) {
MessageBox(NULL, L"Cannot load image!", L"Error", MB_OK | MB_ICONERROR);
}
Update();
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine,
int nShow) {
MSG msg;
InitApp(hInstance);
while ( GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
</windows.h> Thanks for any help
|
|
|
|

|
How can I draw text on the alpha window? Do I have to draw the text into the bitmap and then premultiply it after ? anyone have an example of how to do this:?
|
|
|
|

|
Hi,
This is real world article. How to use controls (ie, button, editbox, ...) in layered windows. Any help?
Thanks,
Pherosiden
|
|
|
|

|
I need the UNICODE version of this Code and i need unicode version of imagdecoder.dll
So far, i have followed the instructions and have not been able to build a unicode version. Can anyone help me?
|
|
|
|

|
I have MS Visual Studio 2005 (no SP) and "anydec.h" is missing. I couldn't find it over internet, so please someone send me it, armaza@mail.ru. thancks.
|
|
|
|

|
The exe file works great but when i open the dsw (project file) in visual c++ 6.0
and compile it i get about 5 compiler errors saying "identifier undeclared".
I tried everything but nothing works.
|
|
|
|

|
Hey,
gr8 work man... actually have implemented alpha compositions equations as well.. but i dont have enough test images, specially the ones with some meaningful per-pixel alpha.
I downloaded what is here on this page but would be gr8 if you could share more or give me pointer to get'em.
Regards,
Ninad
|
|
|
|

|
Dude
this is good... copied or not copied this was the only excellent working example of Pixel Blending of Dialog which I could find anywhere.
And after all we all learn from each other. But what counts is the effort put up by someone to actually post this on the internet is awesome. Remember, Man is a mimicking animal
Good going dude
Glax
|
|
|
|

|
I don't know how to add control to the dialog when i use UpdateLayeredWindow API.Because WM_PAINT message can not send.Can you give me some methods to solve it.Thank you!
|
|
|
|

|
Hi
I have an application that constantly is updating its image.
Now when I place a layered transparent window on the top of it -
I made one with your application using color keying instead of alpha -
then I observe with Windows Task Manager that the CPU time of my
application goes from 3 to 5% to 20 to 25%.
Now my question is, is Window really that bad in handling layered windows
or am I doing something wrong.
Can I make an overlay with markers/cursors for my application in another
way?
Jens M P
|
|
|
|
|

|
D:\perpixelalpha\perpixelalphaDlg.cpp(251) : error C2065: 'WS_EX_LAYERED' : undeclared identifier
D:\perpixelalpha\perpixelalphaDlg.cpp(283) : error C2065: 'AC_SRC_ALPHA' : undeclared identifier
D:\perpixelalpha\perpixelalphaDlg.cpp(287) : error C2039: 'UpdateLayeredWindow' : is not a member of '`global namespace''
D:\perpixelalpha\perpixelalphaDlg.cpp(287) : error C2065: 'UpdateLayeredWindow' : undeclared identifier
D:\perpixelalpha\perpixelalphaDlg.cpp(288) : error C2065: 'ULW_ALPHA' : undeclared identifier
I'm not too conversant with MFC, but I'm getting these all the time, no matter what. I do have the sdk, I try putting the winuser.h everywhere, it's not taken apparently. It's a mystery to me how this thing gets built.
|
|
|
|

|
This article is bad! Writer has stolen code he does not under stand! Article also does not show proper way to do this.
Code he use for premultiply alpha is stolen from Feng Yuans book. Image drawing is from Free Image library.
But even worse, here is proof that this article is broken. Try to draw an big line across image. Make one line of solid blue (rgb(0, 0, 255)), like this in CPerpixelalphaDlg::DoUpdateDummyDialog
// get the bitmap dimensions
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// ADD THIS CODE
CPen kPen;
kPen.CreatePen(PS_SOLID, 4, RGB(0, 0, 255));
dcMemory.SelectObject(&kPen);
dcMemory.MoveTo(0, 0);
dcMemory.LineTo(bmpInfo.bmWidth, bmpInfo.bmHeight);
// ADD THIS CODE
// get the window rectangule (we are only interested in the top left position)
CRect rectDlg;
wnd.GetWindowRect(rectDlg);
You see what happen....
|
|
|
|

|
...MyApp.cpp(136): error C3861: 'UpdateLayeredWindow': identifier not found, even with argument-dependent lookup
Working on Win XP SP2, have latest PSDK installed.
tried everything, nothing works.
Any thoughts ?
S. Wininger
|
|
|
|

|
I dont understand what are you doing in this section of
your code
Fuction PreMultiplyRGBChannels needs for working
with WinAPI poligons?
void PreMultiplyRGBChannels(CBitmap &bmp, LPBYTE pBitmapBits)
{
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// pre-multiply rgb channels with alpha channel
for (int y=0; y |
|
|
|

|
C:\pix\perpixelalpha\perpixelalphaDlg.cpp(288) : error C2039: 'UpdateLayeredWindow' : is not a member of '`global namespace''
C:\pix\perpixelalpha\perpixelalphaDlg.cpp(288) : error C2065: 'UpdateLayeredWindow' : undeclared identifier
Please help me.....
|
|
|
|

|
Hello
If I have to show several images once, can anybody tell me how to do with this article.
|
|
|
|

|
Despite having followed all the instructions the article outlined in order to obtain a working sample showing Alpha Blending, and the many times I've reread the instructions to make sure I wasn't omitting (or overlooking) anything, and despite having obtained a clean compile and link, I have not been able to see any Alpha Blending showing when I run the executable sample. I say this because moving the slider at any range does not produce any blending effect.
Both the "imgdecoder.dll" and "imgdecoder.lib" files are present in the 'bin' folder of the project directory. (I also have the lastest SDK installed on my machine.)
I am very interested in seeing this sample work, and would like to continue making progress with it in that direction.
Thanks for any insight you can offer in this regard. (I'm using VC++ 6.0 and Win2K.)
William
Fortes in fide et opere!
|
|
|
|

|
Great Article, you got my 5. I've been toying around with this a bit and I'd like to build an ActiveX control that is alphablended against it's owner.
I've tried setting the WS_EX_LAYERED style for the control's window and using UpdateLayeredWindow (which returns the same error it returns if you haven't set WS_EX_LAYERED) and I've tried building a windowsless control and using alphablends in OnDraw(), neither have worked. Does anyone know how to do this or have ideas on what else to try?
Eric Hansen
ehansen@pmsi.cc
|
|
|
|

|
Great Article, you got my 5. I've been toying around with this a bit and I'd like to build an ActiveX control that is alphablended against it's owner.
I've tried setting the WS_EX_LAYERED style for the control's window and using UpdateLayeredWindow (which returns the same error it returns if you haven't set WS_EX_LAYERED) and I've tried building a windowsless control and using alphablends in OnDraw(), neither have worked. Does anyone know how to do this or have ideas on what else to try?
Eric Hansen
ehansen@pmsi.cc
|
|
|
|

|
Does someone know why when i try to compile it on VS6.0 i get the:
'AC_SRC_ALPHA' : undeclared identifier
Errors?
I looked in my .h files and it is not decleared, why i don;t have it?
DataDuck
|
|
|
|

|
Hi all
A nice code to work with. I am facing a problem when I am compling my code with Project settings having _UNICODE defined. it gives me a linking error
error LNK2001: unresolved external symbol "unsigned long __stdcall
ImgNewDIBFromFile(void *,unsigned short const *,void * *)"
(?ImgNewDIBFromFile@@YGKPAXPBGPAPAX@Z)
Please I needed ur help badly
thanks & regards
Amit
|
|
|
|

|
I've put controls on the dummy dialog. You can press a button on the dialog, you just can't see it. I guess if there's no WM_PAINT message being sent to the dialog then it can't be sent down to the other controls. Can anyone direct me to some help on how to make any controls appear on this dialog?
Thanks,
azmodius
|
|
|
|

|
Hi all,
Does this support converting images to PCX, preferably 2 bits per pixel.
Thanx
Nilesh
|
|
|
|

|
What does this do exactly?
void PreMultiplyRGBChannels(CBitmap &bmp, LPBYTE pBitmapBits)
{
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// pre-multiply rgb channels with alpha channel
for (int y=0; y |
|
|
|

|
Is there a way to make this work on Windows 98 and ME ?
|
|
|
|

|
Hi,
I just installed the latest Platform SDK, aug 2001 release. I've integrated it in Visual C++ 6.0 by adding the SDK include and lib directories before the old ones, like the documentation says. But i still can compile code using the UpdateLayeredWindow function it still give an error C2065 "UpdateLayeredWindow" : undeclared identifier.
What is wrong ? Any clues ?
Best regards.
Johan Janssens
JJanssens@mail.ru
|
|
|
|

|
Hello,
Does anyone have an example of per pixel alpha transparency (like this one) implemented with DirectDraw? I can not even create an alpha surface ( DDSCAPS_ALPHA ).
SOS!!!
Nick
|
|
|
|

|
I was curious if any1 has been able to successfully integrate controls with the alpha blended windows in this example? If so please explain your methodology.
Thanks
P.S To the author: Great job
Happy Programmer
|
|
|
|

|
Hi the sample application works ok in 16bpp. But when I run the application in 32bpp then the images are not shown correctly. They are always transparent. It seems that Windows or the application is doing something wrong with the alphachannel. If you would like to see what I mean then I can send you screengrabs of the situations.
I am working with Windows2000 professional SP1 and GeForce videocard with nvidia 6.50 drivers.
|
|
|
|

|
Where can I get the SDK so I can compile the project ? (WS_EX_LAYERER and others doesn't exist).
Thank
|
|
|
|
|

|
The PNG fileformat is an excellent choice for such images! It (also) features a 32bpp format with an 8b alphachannel.
|
|
|
|

|
I have changed the sample images from PSP v7.0 to PSP v6.0 file format.
Rui Lopes
|
|
|
|

|
Hi,
very well done, exactly what I was looking for, but I can't open the psp files with PaintShop Pro 6.
PaintShop can't read the files
Do I need Version 7.0?
CU
Max
|
|
|
|
|

|
1: are you saying that you won't allow anyone to use this in production code ( i.e. as a small portion of a program that will be sold ) ??? Not that I want to anyhow, I'm just curious as to your position.
2: How fast is this ? I've done a program that allows me to set transparancy levels on Win2K windows ( although not per pixel ) and the end result is untolerably slow to use ( which is Win2K's fault ). Are your end result Windows pretty or useable ( note: this is not a criticism - either way it's cool, and usability is M$'s fault, not yours ).
3: I've not looked at the project ( I don't run Win2K, although I have it sitting here waiting for me to reinstall ), how do you use the PSP file format ? I'm pretty stoked to have got hold of it - do they allow other people to use it ( I'm thinking I might add PSP file reading/writing to my paint program )
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|

|
where did you get your PSP code from? or, if you wrote it, where did you get the specs?
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Demonstrates how to create per pixel alpha blending windows
| Type | Article |
| Licence | |
| First Posted | 30 Mar 2001 |
| Views | 327,984 |
| Bookmarked | 107 times |
|
|