How to set the transparency

Discussions about image processing and document imaging.
Post Reply
louis
Posts: 55
Joined: Tue Apr 28, 2009 6:18 pm

How to set the transparency

Post by louis » Tue Nov 30, 2010 9:16 pm

Hi Loic,

I would like to transform a fully black image to a semi-transparent image.
Here is the code :

Code: Select all

    GDV_File.DisplayFromFile("c:\opacity.bmp")   ' this file is a black rectangle
    GDI_Tmp.SetNativeImage (GDV_File.GetNativeImage)
    GDI_Tmp.SetTransparency(128)
    GDI_Tmp.SetTransparencyColor(GDI_Tmp.argb(255, 0, 0, 0))
    GDV_File.SetNativeImage (GDI_Tmp.GetNativeImage)
When I use this code or try other parameters than 128 and 255, I get always a fully transparency or a full opacity.
Thanks for your help.

Louis

Tom Moran
Posts: 102
Joined: Thu May 24, 2007 9:41 am
Location: Phoenix, Arizona

Re: How to set the transparency

Post by Tom Moran » Tue Nov 30, 2010 9:41 pm

Hi Louis:

If it were me, I would load the image into the Imaging object, not the viewer.

Code: Select all

    GDI_Tmp.CreateImageFromFile("c:\opacity.bmp")   ' this file is a black rectangle
    GDI_Tmp.SetTransparencyColor(GDI_Tmp.argb(255, 0, 0, 0))
    GDI_Tmp.SetTransparency(128) 'or whatever level desired
    GDV_File.SetNativeImage (GDI_Tmp.GetNativeImage)
Remember, the transparency range is -255 to +255.

Tom

louis
Posts: 55
Joined: Tue Apr 28, 2009 6:18 pm

Re: How to set the transparency

Post by louis » Wed Dec 01, 2010 5:47 pm

Hi Tom,

With your code, I get a certain transparency : the black image is grey.
But I would like to see (with a certain transparency) a picture which is behind the viewer. So, I do BackStyle = 0 (transparent). In that case, the black image is not transformed whatever the transparency value, it's fully black and I don't see the background picture.
Is it possible to that ?
Does a gif image with some transparency solve this ? Or something else...

Louis

Tom Moran
Posts: 102
Joined: Thu May 24, 2007 9:41 am
Location: Phoenix, Arizona

Re: How to set the transparency

Post by Tom Moran » Wed Dec 01, 2010 6:00 pm

Hi Louis:

Instead of using separate images, why not just draw a transparent black rectangle, sized to the image, on top of the image using whatever transparency level you desire. If you need to restore the original image, then make a clone of the image before drawing the transparent rectangle. That way you can restore the original.

To really give you a good suggestion I would need more information on what exactly you are trying to do and what is the final output. For example, once you've achieved the transparent black over the picture would you need to restore the original image? Will you save that image with the transparent black, etc.

Tom

louis
Posts: 55
Joined: Tue Apr 28, 2009 6:18 pm

Re: How to set the transparency

Post by louis » Thu Dec 02, 2010 2:13 pm

Hi Tom,

I just want to display a picture and, over it, a 50% opaque black rectangle in order to simulate a certain transparency.
As I use GDPicture for other purposes, I try to use it for that because, with the VB6 standard controls, we cannot display this kind of thing.
I don't want to save the result but I would like to select any background picture (which can be animated).

Louis

Tom Moran
Posts: 102
Joined: Thu May 24, 2007 9:41 am
Location: Phoenix, Arizona

Re: How to set the transparency

Post by Tom Moran » Thu Dec 02, 2010 4:01 pm

Okay, Louis. I'm still not exactly sure what the purpose of your program/display is, however, there are a few ways you can go about achieving/displaying transparency of an image.

In almost all cases it would be best if you first load the image in the Imaging object, to obtain a reference ImageID, and then apply transparency routines. Once you've finished applying whatever effects/filters, etc. then display the image in the viewer.

You can directly apply transparency to the image itself without overlaying a rectangle or another image. Look at the DrawImageTransparency Method in the GDPicture Help File.

Hope this helps.

Tom

louis
Posts: 55
Joined: Tue Apr 28, 2009 6:18 pm

Re: How to set the transparency

Post by louis » Fri Dec 03, 2010 5:27 pm

In fact, I probably want to do something not possible with the viewer : I would like to display an image and, over it, display something like a filter. So, the image will be displayed with a certain opacity.

In VB6, it seems that is not possible if we use the standard controls. This is the reason why I try to use the GD viewer.
In the VB form, I put an image, I put over it the viewer with a transparent style (which is 100%), so I see the image.
Then, I load a rectangle in the viewer with a transparency. And I cannot see the image behind the viewer.

Maybe a simple image control displaying a GIF file is enough... But I have no efficient GIF editor.

Louis

Tom Moran
Posts: 102
Joined: Thu May 24, 2007 9:41 am
Location: Phoenix, Arizona

Re: How to set the transparency

Post by Tom Moran » Sat Dec 04, 2010 8:27 pm

Hi Louis:

If I understand you correctly then you can do that. The following code loads an image in the Imaging object. It then draws a semi-transparent rectangle over the image. It then displays the image and transparent rectangle in the viewer. Start a new project and put in your license information and the path of the image you are working with.

Code: Select all

 Dim nImageID As Long
 Dim TranspNum As Long
 Call Imaging1.SetLicenseNumber("xxxx")
 Call GdViewer1.SetLicenseNumber("xxxx")
 TranspNum = 100
 GdViewer1.BackColor = vbWhite
 nImageID = Imaging1.CreateImageFromFile("C:\mypicture.jpg")
 GdViewer1.Height = Imaging1.GetHeight * Screen.TwipsPerPixelY + 100
 GdViewer1.Width = Imaging1.GetWidth * Screen.TwipsPerPixelX + 100
 Call Imaging1.DrawFillRectangle(0, 0, Imaging1.GetWidth, Imaging1.GetHeight, Imaging1.argb(TranspNum, vbWhite, vbWhite, vbWhite), True)
 Call GdViewer1.SetNativeImage(nImageID)
You control the level of transparency of the rectangle by adjusting the TranspNum variable (0-255). If that's not what your looking for then I don't understand what you want.

Tom

louis
Posts: 55
Joined: Tue Apr 28, 2009 6:18 pm

Re: How to set the transparency

Post by louis » Mon Dec 06, 2010 12:58 pm

I didn't try to use your code but it should very probably work but ... I would like to use the viewer just as a filter in order to use it on any background, whatever it is (form, picture, image, text, ...).

So, the best solution is probably a transparent GIF image on the form, picture, ...

Louis

louis
Posts: 55
Joined: Tue Apr 28, 2009 6:18 pm

Re: How to set the transparency

Post by louis » Tue Dec 07, 2010 12:37 pm

Hi Tom,

I think that ... I can use GD to create the image instead of using an editor ! Thanks to your last code, I should be able to create a GIF file with the size and transparency that I want.

The only problem is own to VB6 : image controls cannot be put over controls like text boxes.
So, it seems that I have to use VB 2008 ... !

Louis

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest