• 0

[vb .net] Alpha Blended PNG's as form BG?


Question

Does anyone know a link to a simpler tutorial on how to use PNG's with alpha blending and set them as a form background so that the form takes the shape of the png? Basically, free form skinning basing the shape on the PNG with alpha blending so I can use things like drop shadows. Anyone?

Also, is the alpha blending support still the same in 2.0 as it is in 1.1?

Link to comment
Share on other sites

18 answers to this question

Recommended Posts

  • 0

In 1.1 it does a composition against the background when you Show() the form, but doesn't update when moving the window around, unless you force a refresh during/after movement. Not tried on 2.0 yet.

Link to comment
Share on other sites

  • 0

I need to know how to do it though. Even when setting the form bg color to the same color as the trans key, I still get the magenta dots where it's alpha blended. I'm not that great at this stuff, so I really need something I can read through that's not too complicated.

Link to comment
Share on other sites

  • 0

You werent the only one having troubles with that. Past investigations in the Usenet revealed loads of Interop hacks with GDI, which was something I tried to avoid. I'll take a peek at WinForms 2.0 tho.

Edited by Tom Servo
Link to comment
Share on other sites

  • 0

I don't believe it! It automatically updates the background in .NET 2.0.

Regarding the color key fringes, IIRC GDI doesn't support 8bit alpha masks, so it's either completely transparent or not. I suppose you are using bitmaps with an alpha channel? The magenta dots are likely the result of noise/greyscales in that alpha map, if you're using them. It either needs to be full white or full black, grey breaks the transparency key.

Link to comment
Share on other sites

  • 0

Well, yeah it was semi transparent pixels from the alpha transparency in the PNG file. I really wish to keep the alpha blending so I can do things like drop shadows in the background image.

Link to comment
Share on other sites

  • 0

Let me check some old splashscreen code, that is if I find it again. I had a transparent shadow there. If the new updating in .NET 2.0 works there as well, then alphablending should work. I just forgot how I did it there (it didnt update when moving in 1.1).

Link to comment
Share on other sites

  • 0

thanks. I saw an app made over at gfxoasis, and it inspired me to start coding again but I haven't been able to find anything on alphblended shadows in png's and such.

Link to comment
Share on other sites

  • 0

good job ######. I did ask it over a damn year ago and now I am asking now and Tom is giving me hope and trying to help me out. Would you prefer I bump a year old thread? I gave up on it then, but am interested in learning it now. Moron.

And your answer does what? I know I have to use GDI+, thanks, but that gets me where? I've been googling gdi+ all after noon but found nothing useful enough. You, sir, are a general idiot. Thanks for nothing. If you wanted to make me look dumb, you failed miserably.

Link to comment
Share on other sites

  • 0

I found the splashscreen code afterall, after running into some old backup RARs I made when a disk was failing. I am dead sure that I had transparent shadows on that splashscreen, because I was so proud of it. However under WinForms 2.0, it renders it against a background color. The conclusion is that they've changed stuff, so you don't get around doing some ugly hacks.

Link to comment
Share on other sites

  • 0

Ok, so where do I go now Tom? You know ALOT more than me so I'm not as quick as picking up on where you are leading me.

edit: Tom, I have to run out now. Thanks for all you've done so far tonight. I'm hoping you can just point a n00b like me in the right direction. I'll check back in later tonight.

Link to comment
Share on other sites

  • 0

Actually, I have no clue. I never tinkered with GDI+, when I quit C, there was still only regular crappy GDI. I'm actually a bit ****ed myself, because I can't do shadowed splashscreens anymore. And I've no clue about a work around (yet?).

Link to comment
Share on other sites

  • 0

Here's what I found, and I looked at the example and this looks like its exactly what you need.. the only problem is its in C#... anyway, take a look and see if you can figure it out or figure out whats required..

http://www.codeproject.com/cs/media/perpxalpha_sharp.asp

btw, this example looks awesome :)

in case you dont have an account and dont want to make one (required to download source), heres the source code and sample application attached:

Link to comment
Share on other sites

  • 0

According to the guide:

To use this code you need to include PerPixelAlphaForm.cs file in your project
So.. since in 2003 you can't load c# files in vb.net projects, I compiled the c# file into a dll (attached) and added a reference to it from the vb project..
, create a class that inherits from PerPixelAlphaForm, load a bitmap using System.DrawingImage.FromFile static method and then call the PerPixelAlphaForm.SetBitmap method.

It would seem the next step is to create a class that inherits from PerPixelAlphaForm..

Inherits PerPixelAlphaForm

But... I'm getting an error:

Type expected.

in which "PerPixelAlphaForm" is underlined with a blue squigly line.. thats where im stuck :/

edit: forgot to attach file

Edited by todd`
Link to comment
Share on other sites

  • 0

I tried using the c# dll with vb.net but couldn't make it work, so i tried to translate the code from c# to vb using this and also using my brain, anyway now i can show the form and move it around! :)

And now all we need is to do something useful with that.

Heres the source for you guys.

PerPixelTest_VB.zip

Link to comment
Share on other sites

  • 0

Thank you lagmann. I hate to have to use someone else's code and have to give them credit, but iy'll be a fall bakc plan worse comes to worse that I can't figure it out and recode it from scratch.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.