We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › pasting transparent img
Page Index Toggle Pages: 1
pasting transparent img (Read 1619 times)
pasting transparent img
Feb 22nd, 2007, 4:55am
 
so.. it's obvious that i could just convert any images i need transparent sections in to .gif, but i'd rather keep a lot of them in other formats.

is there a way for me to use a function similar to image(...) that will paste the image using a color value as the transparent portion?

i would much rather use a function that exists instead of writing my own. if i have to write my own, i will probably wind up going with transparent .gifs instead. Tongue

thanks in advance,
Re: pasting transparent img
Reply #1 - Feb 22nd, 2007, 8:32am
 
just save the alpha as a seperate greyscale-image and use:

http://processing.org/reference/PImage_mask_.html

F
Re: pasting transparent img
Reply #2 - Feb 22nd, 2007, 6:53pm
 
so maybe the mask would fill all "transparent" pixels in white, the "opaque" pixels in black?

or vice versa?
Re: pasting transparent img
Reply #3 - Feb 22nd, 2007, 6:58pm
 
wait.. i just had an epiphany (or something like it). i believe i should be able to load the color value of the upper-left-hand corner of the image i wish to paste (coord 0,0) and dynamically generate a mask for the image.

any color value of the original matching the transparent color value will be pasted to the mask as a "transparent" pixel. any other color value will be pasted to the mask as an "opaque" pixel.

i'm going to try that out when i get back from class this afternoon, and post my results.

thank you for pointing out this function! i knew there had to be something out there. Smiley
Re: pasting transparent img
Reply #4 - Feb 22nd, 2007, 8:38pm
 
You could use a PNG with alpha.
Re: pasting transparent img
Reply #5 - Feb 22nd, 2007, 8:45pm
 
haliphax wrote on Feb 22nd, 2007, 6:53pm:
so maybe the mask would fill all "transparent" pixels in white, the "opaque" pixels in black

or vice versa


right, have the mask-image be greyscale and do something like:

PImage img = loadImage("myImage.jpg");
PImage imgMask = loadImage("myImageMask.jpg");
img.mask(imgMask);

but then you might just as well rethink your dont-want-to-change-type policy and use PNG for all images as dave pointed out ... Smiley

F
Re: pasting transparent img
Reply #6 - Feb 23rd, 2007, 2:57am
 
i think i can pull it off by generating a pixel array on-the-fly for the mask based on the first pixel of the image to be displayed.

thx for the help!
Page Index Toggle Pages: 1