Setting transparency

Discussions about image processing and document imaging.
Post Reply
bjcam
Posts: 41
Joined: Tue Jul 12, 2011 10:58 am

Setting transparency

Post by bjcam » Thu Mar 15, 2012 12:57 pm

Hi
I am trying to set the transparency of an image where I want all the white to be transparent so that the background colour of the GdViewer shows through.
I have tried using:
oGdPictureImaging.SetColorKey(ImageID, oGdPictureImaging.ARGB(255,240,240,240),oGdPictureImaging.ARGB(255,255,255,255))
but this just makes all the white go black!
I instead tried to use:
oGdPictureImaging.SetColorRemap(ImageID, arcolor)
using the code example but I got errors.
How can I change the white range of colours on an image to be transparent, or to be a different colour?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Setting transparency

Post by Loïc » Thu Mar 15, 2012 1:05 pm

Hello:

Code: Select all

Imaging1.ConvertTo32BppPARGB(ImageID)
Call Imaging1.SwapColor(ImageID, Color.White, Color.Transparent, 90)
Let me know if it is OK.

Kind regards,

Loïc

bjcam
Posts: 41
Joined: Tue Jul 12, 2011 10:58 am

Re: Setting transparency

Post by bjcam » Thu Mar 15, 2012 1:19 pm

Hi Loic
Thanks for the reply. I got a 'Object reference not set to an instance ..' error on the SwapColor method?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Setting transparency

Post by Loïc » Thu Mar 15, 2012 1:30 pm

How to reproduce the problem ?
Or at least, could you provide more info ?

bjcam
Posts: 41
Joined: Tue Jul 12, 2011 10:58 am

Re: Setting transparency

Post by bjcam » Thu Mar 15, 2012 1:53 pm

I use a class for the GdViewer and manipulate the images within the class. All works well. This is part of the code:
p_CurrentImage = oGdPictureImaging.CreateGdPictureImageFromFile(imgPath)
Me.DisplayFromGdPictureImage(p_CurrentImage)

Then I added:
oGdPictureImaging.ConvertTo32BppPARGB(p_CurrentImage)
Call oGdPictureImaging.SwapColor(p_CurrentImage, Color.White, Color.Transparent, 90)

The second line triggers the null object error.

bjcam
Posts: 41
Joined: Tue Jul 12, 2011 10:58 am

Re: Setting transparency

Post by bjcam » Thu Mar 15, 2012 5:18 pm

Ok, by changing ConvertTo32BppPARGB to ConvertTo32BppARGB it worked!
Why is this?
Thanks

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Setting transparency

Post by Loïc » Thu Mar 15, 2012 5:25 pm

I can't reproduce the problem. Are you using the latest version ?

bjcam
Posts: 41
Joined: Tue Jul 12, 2011 10:58 am

Re: Setting transparency

Post by bjcam » Thu Mar 15, 2012 5:44 pm

It looks like I am not using the very latest version. I will download it and try it.
Most of the images I deal with are grayscale - would that cause the problem with ConvertTo32BppPARGB?
And if the image was already colour, would I have a problem instead with ConvertTo32BppARGB? Is there a way of detecting whether the image is grayscale?

bjcam
Posts: 41
Joined: Tue Jul 12, 2011 10:58 am

Re: Setting transparency

Post by bjcam » Thu Mar 15, 2012 7:21 pm

hi Loic
I have just installed the latest version and ConvertTo32BppPARGB works now!
The current version of GdPicture.NET.dll shows as 8.5.0.20.
I thought the latest version was 8.5.19?

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest