2uzhan.com
Advertisement
Now Place:2uzhan.com » why Transparent image background is still shown?

why Transparent image background is still shown?

Visual Basic .NET @ August 9, 2006   Views:0

Hi all,

I hope someone can help me with this.

I have made transparent gif images using photoshop hoping that when i use them in windows forms picturebox the background won't be visible . They blend with the different backgrounds but still there is a rectangular background around the picture with the same color of the picturebox background. why is this happenning?
And also when I overlap two images I want them to be see through so that the picture beneath is visible.

Thank you all
Sai

--------------Solutions-------------

Hello Sai!
Did you follow these steps for creating a transparent gif :
In Photoshop select New
Select Transparent in the Contents groupbox, select OK
Then, when saving:
File, Save for Web
Make sure GIF is selected for file type
Transparency checkbox is selected ¿
When I do the above it's fine in VB

Does it help ¿

hello Hannes,

Well Actually I converted gif images i had already to transparent gif images using photoshop .

I followed the following steps:

file ->open->open abd.gif file

using Magic eraser tool clicked on background which then converted into checkered background.

file->save for web

Made sure transparency and gif were selected

then save it as def.gif

Did I miss anything here?

for your reference i am attaching 2 images one before the transparency and another after making it transparent.

Hello Sai!

I looked at both your pictures. The converted one does have a transparent background, so there is nothing wrong with the picture. The reason you see the picturebox's background is because the picture's background is transparent. The problem lies with the pictureboxes and not the pictures.

Do you want a complete transparent background for the Picturebox ¿

Hello Hannes

Thank you very much for taking time to look at my problem.

As we know there is nothing wrong with the pictures i think it's worth explaning what is happenning in my case then,Actually i am using RImage control I found in the following article:

http://www.codeproject.com/vb/net/rimage.asp

it just acts like a picturebox. " showthrough" property should work for me as author says that "ShowThrough will determine whether or not space not used by the image will be transparent and show the control below it. This is accomplished using regions."

but this doesn't seem to be working in my case.

I am attaching this part of my project here could you please have a look at it?

CreateTransRegion function is called if showthrough property is set.

I know it looks confusing but once u look at the project you will understand a bit i guess

Thanks a lot for your help.

sai.

Hi!

I'll have a look at it , and try my best to figure out what's going on.

We'll get it fixed, one way or the other

Thank you very very much ,That gives me hope Hannes.

Hello again Sai!

I added the RImage control to my project. I added the GIF you made Transparent to it. What I then did, was to set the RImage's BackColor to Transparent, by clicking on the BackColor property, selected the Web tab, then Transparent is on top of the list. I then set the Form's backcolor to a different color (blue), and both the picture and the form had the same color. have a look at the screenshot.

Does that help ¿

Is this what you mean?

I did this (see screenshot) by

1. Creating a panel to hold the picture box.
2. Set the BackColor property of the panel.
3. Set the TransparencyKey for the form to the same colour as the the BackColor of the panel.
4. Placed a picture box inside the panel with your transparent background image and voila!

Or have I missed the mark?

Thanks hannes

But try to add two Rimages and when you overlap them (as RImage has drag and drop abilities in the project I attached) you can see the blue (in your case) rectangular background and you won't be able to see the picture beneath it.

That's my problem

Thank you
Sai
Hey ANimalX,

Thanks for your reply Trasparency key seems to be working but it shows mainform or what ever is behind this child form how can i overcome this? Any idea?

And also if i overlap two images they are not transparent again and for example after placing the images on panel if i want Mouseclick events it is not possible.

Thanks
sai

Hello again Sai!

This was not easy

There is a process called AlphaBlending, which enables us to blend colors from a "background" to colors from a "foreground". Meaning that if we have 2 images, which is the case here, we can blend them into one another.

I am attaching a sample (which kept me up again all night) which blends 2 drawn shapes OR 2 Images.

The more you click the Draw Shapes button, or the Draw Image button, the more it blends.

Have a look at it please, and see if it can help you out, but I honestly think that you will be more than satissfied with the results.

PS: I told you don't worry, we'll get it fixed - like Guns n' Roses say : All we need is Patience

Have fun

Hannes:

That is a nice piece of code! Essentially, you are drawing the the pictures a multiple times with the same value of i. So I put the last draw statement in a loop and the desired effect can be achieved in one click of the button.

Dim k As Integer
For k = 0 To 10
pic.CreateGraphics.DrawImage(img2, New Rectangle(50, 50, 200, 150), 0, 0, img2.Width, _
img2.Height, GraphicsUnit.Pixel, i)
Next

All we need is to adjust the maximum value of k in the loop to get the desired effect.

Thanks for this very useful code.

Sorry, correction to my last reply: in the loop, we have to put draw both images to get the desired effect:

Dim k As Integer
For k = 0 To 10
pic.CreateGraphics.DrawImage(img, 0, 0, 200, 150)
pic.CreateGraphics.DrawImage(img2, New Rectangle(50, 50, 200, 150), 0, 0, img2.Width, _
img2.Height, GraphicsUnit.Pixel, i)
Next

Thanx for your kind words Gizmo!
And thanx for those corrections and improvements!
I guess my brain stopped working at 5 AM this morning..

Tags:
© 2018 2uzhan.com Contact