Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi,

 

 

im trying to display an image using its embedded alpha as transparency. but it seems to ignore the alpha channel.

i thought this would be automatic, but apparently not

 

im using a 32bpp ARGB .bmp file

 

Bitmap image(L"blah.bmp");

graphics.DrawImage(image,x,y);

 

ive trawled through msdn and all the gdi+ tuts i can find but they only mention using matrices to set a uniform alpha across the whole image.

 

I did manage to find a tutorial for doing using standard gdi, but that kinda defeats the whole point.

 

thanks.

Mr Plough.

Posted

wierd considering it supposedly supports per pixel alpha.

 

I guess i could load the alpha channel as a greyscale bitmap and use it to set the alpha manually.

 

hmm........

Posted

.png supports 256 levels of transparency, but it doesnt show an alpha 'channel' in photoshop.

 

i tried loading one using gdi+ and it ignores all but full transparency. which makes it about as usefull as a gif.

 

whether this is a gdi+ limitation or me being crap remains to be seen :P

Posted

Looks like it is made with DirectX, not GDI+

 

- Moby for helping me out with making Orbit transparent (thanks for pointing out how to get it OUT of Direct3D :P)

Gamer extraordinaire. Programmer wannabe.
Posted (edited)

the app interface is rendered in Direct3D, then blitted to a 32bit GDI+ image to be blitted to the screen (that's why i say "getting OUT of Direct3D")... but the item config dialog is plain GDI+ and it SHOWS PNGs with per pixel alpha blending.... so does the configuration dialog.

 

if ur really doubting me, download the thing... look at it... delete it after if u want...

 

i searched this forum and did posts while programming that... look around and u will find my posts...

Edited by Menge
Menge
Posted

i dont doubt u dood, i just cant get the f*@£ing thing to work.

 

I loaded your ring.png file, just in case im making the file wrong -

 

Bitmap image(L"ring.png");

graphics.DrawImage(&image,x,y);

 

and it rendered the centre transparent, but the edges are NOT blended.

 

I cant post the image because my web space is down at the moment.

 

If you can tell me what im doing wrong, please do so.

Posted

this is all i do and it works :P

 

this.IconBgDisplay.Image=Image.FromFile(FileBrowse.FileName);

 

there IconBgDisplay is a PictureBox.

 

nothing special... dunno why it doesn't work there.

Menge
  • *Gurus*
Posted

Png files should work fine in GDI+ (and yes, they have full transparency information) as long as they're never added to an ImageList. This corrupts their alpha channel.

 

Have you experimented with drawing them to a graphics surface using DrawImage() in the Paint event of a control?

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

hmm.

 

i think this can only be caused by the way ive constructed my window. i dont use forms, and am drawing directly to the main window which is set to WS_EX_TRANSPARENT and WS_EX_LAYERED.

 

msdn doesnt mention any limitations, and all the functions return OK.

 

i dont really get the SetLayeredWindowAttributes() function. the colorkey setting works fine, but if you set it to LWA_ALPHA with 0 opacity, anything you draw on the window is invisible regardless of alpha. if you set it to anything other than 0, you lose the transparency of the window. and it STILL ignores anything other than fully transparent!

 

the idea is to get full alpha control on a transparent desktop overlay, much the same as Menge's app (although im not making a dock).

 

should i be using forms and controls and such?

Posted

funny... coz that's what i doing...

here's a snip

 

Rectangle dock=new Rectangle(new Point(0,0), new Size(500, ProgramConfig.IconSize));
Microsoft.DirectX.Direct3D.GraphicsStream Image=front.LockRectangle(dock, LockFlags.None);
			
Bitmap b=new Bitmap(dock.Width, dock.Height, Convert.ToInt32(this.Width*ProgramConfig.BMPFIX), System.Drawing.Imaging.PixelFormat.Format32bppArgb, Image.InternalData);

IntPtr Bmap=b.GetHbitmap(Color.FromArgb(0));
IntPtr memDc = CreateCompatibleDC(GetDC(IntPtr.Zero));
IntPtr oldBitmap = SelectObject(memDc, Bmap);

try
{
size.cx=dock.Width;
size.cy=dock.Height;
UpdateLayeredWindow(LabelDisp.Handle, IntPtr.Zero, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, ULW_ALPHA);
if(Disp.Visible && ProgramDoing==ProgramState.Nothing)PopUp(false);
}
finally
{
if (Bmap != IntPtr.Zero) 
{
	SelectObject(memDc, oldBitmap);
	DeleteObject(Bmap);
}
DeleteDC(memDc);
b.Dispose();
Image=null;
front.UnlockRectangle();
}

 

i think u can get something out of it.

Menge
Posted

Does anyone know what Alpha bitmaps are? Sorry to budge in like this but I was looking at the topic name and I was thinking to myself: "What the heck are they talking about?! Well I better ask or skip it"

 

;)

"Reality is fake, Dreams are for real"
  • *Experts*
Posted

A PNG file (like a BMP but a different format) can contain not only the red, green and blue values of every pixel but can also contain an alpha value for each pixel. If drawn using the alpha channel, it allows a blending of the pixel in the PNG file with whatever is currently on the screen.

 

So if the top pixel has an rgb value of 255,0,0 (pure red) and an alpha of 128 and the pixel on the screen where the pixel in the bitmap will be drawn is white, you'll end up with a pink dot. Alpha values go from 0 to 255. If it's 0, there is nothing new drawn to the screen from the bitmap. If it's 255, the pixel in the bitmap is drawn, overwriting whatever was on the screen. Any value in between is a blending of the two pixel colors. In the above, 128 is 50% blending - so blend the pure red with the pure white and you get pink.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • 1 year later...
Posted

How to add controls?

 

I am using the UpdateLayeredWindow function to do per pixel alpha blending. It works great with a png file with alpha channel. (Yes, png does have an alpha channel.) To summarize what people have been saying in this thread. In order to do the transparency you load the png file into a DIB. The DIB can then be loaded into a CBitmap. If you are using .NET you can load it directly from the file. I am not so have to use the libpng library. I created a dialog app which I use to display the image. I used this code as a guide:

per pixel alpha blending example

 

Now that I have that working I need to know how to draw the controls I want on top of that. I want to make them ownerdraw, so if anyone has any good examples of that, I'd apreciate it. I gather I must draw onto the bitmap I create from the png file with the control images. I then will need to figure out how to handle click and key events.

 

I also got it working using the SetLayeredWindowAttributes function, but that only does alpha blending of the entire window to a single value, not per pixel. It will also do a transparancy color, but that looks bad since it doesn't anti-alias. But it does show the controls on the form.

 

Xargon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...