Mr Plough Posted August 24, 2003 Posted August 24, 2003 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. Quote
Menge Posted August 24, 2003 Posted August 24, 2003 BMPs have alpha channels? try using PNGs instead Quote Menge
Mr Plough Posted August 25, 2003 Author Posted August 25, 2003 ARGB BMPs do yes. .png files dont, they have transparency like gifs. im starting to dislike this gdi+ thing..... Quote
wyrd Posted August 25, 2003 Posted August 25, 2003 To be honest I don't think it's possible with GDI+. :( Quote Gamer extraordinaire. Programmer wannabe.
Mr Plough Posted August 25, 2003 Author Posted August 25, 2003 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........ Quote
shouzama Posted August 25, 2003 Posted August 25, 2003 I grant you that .png DO support alpha channel. However, truly don't know if it's possibile to import and use such files with GDI+. Quote
Mr Plough Posted August 25, 2003 Author Posted August 25, 2003 .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 Quote
Menge Posted August 25, 2003 Posted August 25, 2003 dude, ur wrong. PNGs DO have an 8bit alpha component for each pixel. and they DO work with gdi+ aswell: http://www.ecocardio.com.br/orbit/dev0822.jpg Visit The Orbit Project Homepage for more info and a download. Quote Menge
Mr Plough Posted August 25, 2003 Author Posted August 25, 2003 Nice app! Seems to be written in DirectX 9. I'll be happy to be corrected tho. Quote
wyrd Posted August 25, 2003 Posted August 25, 2003 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) Quote Gamer extraordinaire. Programmer wannabe.
Menge Posted August 25, 2003 Posted August 25, 2003 (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 August 25, 2003 by Menge Quote Menge
wyrd Posted August 25, 2003 Posted August 25, 2003 There's no source code included, so I'm not quite sure how it helps. :P Quote Gamer extraordinaire. Programmer wannabe.
Mr Plough Posted August 25, 2003 Author Posted August 25, 2003 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. Quote
Menge Posted August 26, 2003 Posted August 26, 2003 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. Quote Menge
*Gurus* divil Posted August 26, 2003 *Gurus* Posted August 26, 2003 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? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Mr Plough Posted August 26, 2003 Author Posted August 26, 2003 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? Quote
Menge Posted August 27, 2003 Posted August 27, 2003 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. Quote Menge
Diablicolic Posted August 28, 2003 Posted August 28, 2003 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" ;) Quote "Reality is fake, Dreams are for real"
*Experts* Nerseus Posted August 28, 2003 *Experts* Posted August 28, 2003 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 Quote "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
Xargon Posted October 21, 2004 Posted October 21, 2004 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.