Jump to content
Sign in to follow this  
Cool-LV

I wish LV can display translucent PNG or GIF image

Recommended Posts

as my subject, I wish LV can handle or display translucent PNG or GIF image on picture control, sometimes, my PNG image's edge is having translucent looking but LV can not display its realistic face, the edge part lose something, and I have to use Web ActiveX to display it, but this kind of ActiveX is differently handle image data......

Share this post


Link to post
Share on other sites

Or you could build your own, the image data returned from a read png file contains the alpha blending info, if you really want to you could write your own alpha-blending routine.

You would need to get the image behind the picture control and do your calculation but that should be doable.

Ton

Share this post


Link to post
Share on other sites

QUOTE (Ton @ Dec 17 2008, 08:04 AM)

Or you could build your own, the image data returned from a read png file contains the alpha blending info, if you really want to you could write your own alpha-blending routine.

You would need to get the image behind the picture control and do your calculation but that should be doable.

Ton

All right, Ton, I enclosed simple code, there are my query on front panel, I don't think it can be done. Please give your thread, thanks @!

Share this post


Link to post
Share on other sites

Also when you put image on front panel as a decoration transparency smoothness is preserved. I was playing around with scripting trying to dynamically change such decoration, but without success.

Share this post


Link to post
Share on other sites

QUOTE (vugie @ Dec 17 2008, 09:32 AM)

Also when you put image on front panel as a decoration transparency smoothness is preserved. I was playing around with scripting trying to dynamically change such decoration, but without success.

Oh Yup, if we can regard the front panel as a huge picture control, :yes: and dynamically load PNG or GIF image, it is nice too. :thumbup:

Share this post


Link to post
Share on other sites

QUOTE (vugie @ Dec 17 2008, 09:32 AM)

Also when you put image on front panel as a decoration transparency smoothness is preserved. I was playing around with scripting trying to dynamically change such decoration, but without success.

and, I find LabVIEW platform an internal function which is "import picture to clipboard", it is powerful function, it can import many format image, e.g. Jpeg, Bmp, PNG and GIF, animation too, Wow, how NI does this, if we can call this function(even Scripting), it is nice, because We can get image from clipboard. but I fail, though I enabled LabVIEW scripting too.

and I found, if import an animated GIF picture to clipboard, add loop for get image from clipboard and run this code,you would find, the image displaying on picture control is animated too!

Share this post


Link to post
Share on other sites

QUOTE (Ton @ Dec 16 2008, 11:04 PM)

Or you could build your own, the image data returned from a read png file contains the alpha blending info, if you really want to you could write your own alpha-blending routine.

You would need to get the image behind the picture control and do your calculation but that should be doable.

Ton

Ton, is correct.

I have code that I wrote a while ago that do just that and it works like a charm.

PJM

Share this post


Link to post
Share on other sites

QUOTE (PJM_labview @ Dec 18 2008, 06:25 PM)

Ton, is correct.

I have code that I wrote a while ago that do just that and it works like a charm.

PJM

Hi PJM,

Then, would you share that simple code for study ? thanks ?!~

Share this post


Link to post
Share on other sites

QUOTE (Cool-LV @ Dec 18 2008, 04:24 PM)

Hi PJM,

Then, would you share that simple code for study ? thanks ?!~

I am sorry, but I can't share this code.

Here is more info that should help.

As other have mentioned, after reading a PNG file the image data cluster does has the alpha blending info in the image array as [ARGB] (Alpha Red Green Blue).

Once you got the image data of the pixels directly "behind" you new image, you could now recompute each new pixel color with:

ResultingColor = SourceColor × alpha / 255 + BackgroundColor × (255 - alpha) / 255

Note: You need to operate on color plane not on LV color.

I hope this help.

PJM

Share this post


Link to post
Share on other sites

I've done this in the past as well and I can also say the code is quite simple (although I can't share mine either). If you do this, maybe you should post your code to both threads. You can get the color info by unflattening the pixmap and then splitting and joining the 2D arrays or by taking the data directly from the 1D image array and you can get the transparency info from every fourth element in the image array (e.g. by using the decimate array primitive).

Philippe, as I mentioned in the other thread, my code which worked fine in 7.0 doesn't really work in 8.6 and sort of messes up the picture. I didn't look into this, so I don't know the details, but did you run into anything like that?

Share this post


Link to post
Share on other sites

QUOTE (Yair @ Dec 20 2008, 08:27 AM)

Philippe, as I mentioned in the other thread, my code which worked fine in 7.0 doesn't really work in 8.6 and sort of messes up the picture. I didn't look into this, so I don't know the details, but did you run into anything like that?

Nope. Still works fine for me (see below).

Note: Watch the little gradient block as I move it in the image.

PJM

Share this post


Link to post
Share on other sites

Well, the image I saw this happen with has more complex transparency than that and since the code did work fine in 7.0, I would have to blame 8.x. However, as I mentioned, I didn't look into this at all other than seeing that it happened, so the fix would probably not be too hard.

Share this post


Link to post
Share on other sites

Thanks All your guys, all of you are very kind, I appreciate !

maybe, I hadn't gave the clear question, all your help is focus the transparent effect, actually, I want to display the PNG image with its original face. where is translucent where it should be, it is not making whole image is transparent.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

I think the misunderstanding might not be with us.

The method I described earlier works regardless how many transparent area there are in the image.

Below is another short video using a more complex (transparency wise) image.

PJM

Share this post


Link to post
Share on other sites

I would have to agree with PJM. If you look at the last video he posted, you can see this very clearly in the shadows cast by the sequence in the LV logo.

The LabVIEW picture control functions load the alpha channel from PNGs, but the VIs that draw the image discard it. That's why you need to get both the FG and BG image and do the merging yourself. I explained this in more detail in the other thread.

Share this post


Link to post
Share on other sites

thanks all,specially thanks PJM, the function is so cool(from the video, that is what I need ), but the "Create mask.vi" can't not make translucent effect. just transparent. I have no idea to deal with it. :(

Share this post


Link to post
Share on other sites

Wow, I made it, Thanks PJM again (ResultingColor = SourceColor × alpha / 255 + BackgroundColor × (255 - alpha) / 255, it works :thumbup: ) and all you guys. :laugh:

Share this post


Link to post
Share on other sites

Well, if you came up with something, I suggest you post it to both threads in case someone else will want it in the future.

I can say that the code Mike posted already does almost everything you need. It took me about a minute to modify it to handle alpha blending for the entire array and plug it into my code and it worked nicely in 8.6. I guess that means that the algorithm I originally used was wrong, but it's interesting that it did work fine in 7.0.

Share this post


Link to post
Share on other sites

I think you can also use the PictureBox .Net control. It blends automatically with the background.

Share this post


Link to post
Share on other sites

QUOTE (Dirk J. @ Jan 1 2009, 04:31 PM)

I think you can also use the PictureBox .Net control. It blends automatically with the background.

OH yeah, Upstairs's handle is so easy! nice.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.