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 & HelpSyntax Questions › a strange probem with loadImage
Page Index Toggle Pages: 1
a strange probem with loadImage (Read 1039 times)
a strange probem with loadImage
Jan 13th, 2010, 6:10am
 
When i use loadImage to load an image with transparent background,I find the transparent part change to white.Can anybody help me ? I want it is still transparent.
Re: a strange probem with loadImage
Reply #1 - Jan 13th, 2010, 8:38am
 
Show us a small code snippet illustrating your problem, please.
Re: a strange probem with loadImage
Reply #2 - Jan 13th, 2010, 2:38pm
 
I've got something for you (possibly).

I got a similar problem, not when I load the image, but when I display it. If I use set() to display the image, the image shows white instead of transparency. But if I use image(), the transparency works. I guess set() doesn't support alpha. Hope this helps, without your code I can't do more.
Re: a strange probem with loadImage
Reply #3 - Jan 13th, 2010, 8:25pm
 
is my problem similar? (I've just started learning processing)
Running a code from I. Greenberg's book, p.195 'Drawing lines with pixels example' using line:
PImage img = createImage(width, height, RGB);
it draws black lines in on black background

The only possible format parameters for createImage should be only RGB, ARGB, or ALPHA. Still, I replaced 'RGB' with '255':
PImage img = createImage(width, height, RGB); (which should not make sense?)
Processing draws image as shown in the book: black lines on white background.

complete code is below. Thanks.

size(500,300);
background(255);

//used by diagonal lines
float slope = float(height)/float(width);
//this is the line where I replaced 'RGB' with '255')
PImage img = createImage(width, height, RGB);
color c = color(0,0,0);

//horizontal line
for (int i=0; i<width; i++){
 img.set(i, height/2, c);
}

//vertical line
for (int i=0; i<height; i++){
 img.set(width/2, i, c);
}

//diagonal line (TL-BR)
for (float i=0; i<width; i++){
 img.set(int(i), int(i*slope), c);
}

//diagonal line (BL-TR)
for (float i=0; i<width; i++){
 img.set(int(i), int(height-i*slope), c);
}
image(img, 0, 0);
Re: a strange probem with loadImage
Reply #4 - Jan 13th, 2010, 9:23pm
 
Thanks a lot.
The reason is not about loadImage .I find the reason that image.pixels[i] = src.pixels[i];
Re: a strange probem with loadImage
Reply #5 - Jan 14th, 2010, 1:03am
 
Mikhail, first, the format parameter of createImage isn't strongly checked by Processing: if you pass "garbage" there (as long as it is some int), it will try and use some default behavior (perhaps RGB, but get() will always return 0, etc.). Just stick to documented values... Smiley

Next, you should use background() to... change the color of the background. But first, you must switch from PImage (most used to store images loaded with loadImage or very simple pixel per pixel stuff) to PGraphics. Or do a loop to change the color of all pixels before drawing your stuff.
Code:
PGraphics img = createGraphics(width, height, P2D);
img.background(255);


BTW, your problem is not similar, since you don't use loadImage()...
Re: a strange probem with loadImage
Reply #6 - Jan 14th, 2010, 4:46am
 
Thanks...

sorry about confusing simlarities.

* Mikhail
Page Index Toggle Pages: 1