FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   can't get() into BImage
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: can't get() into BImage  (Read 376 times)
GaryFixler


can't get() into BImage
« on: May 22nd, 2004, 1:50pm »

I'm unable to have get(x, y, w, h) populate the pixels of a BImage. Here's a sample of my problem:
 
//---------------------------------------
BImage older, newer;
 
void setup()
{
  older = loadImage("test.jpg");
  size(older.width, older.height);
  image(older, 0, 0);
}
 
void loop()
{
}
 
void mouseReleased()
{
  newer = get(0, 0, 100, 100);
  rect(0, 0, width, height);
  image(newer, 0, 0);
}
//---------------------------------------
 
I just can't seem to get "newer" to grab a piece of the screen. I've tried many variations, including things in loop(). Anyone have any ideas?
 
Thanks.
 

--
Gary Fixler
mKoser

WWW Email
Re: can't get() into BImage
« Reply #1 on: May 22nd, 2004, 5:25pm »

get() is used to read the colour of ONE pixel, and not to copy pixels from one BImage to another...  
...to do this, take a look at copy() and replicate()
 
get()
copy()
replicate()
 
+ mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
GaryFixler


Re: can't get() into BImage
« Reply #2 on: May 22nd, 2004, 8:11pm »

According to the docs, get() is overloaded to allow the passing of x and y, or x, y, w, and h, and returns either a color, or a BImage as a result:
 
http://processing.org/reference/get_.html
 
Perhaps the docs have some old info? Should I report it in the documentation bug section?
 
I'm using a slightly older alpha currently, that doesn't support replicate. I looked it up in the newer docs, though, and it looks nice, as does blend! I'll upgrade soon, but I was just wondering what was going on here. I've also been unable to use newer.set(x, y, c)(nothing happens in the newer image), or newer.pixels[i].
 
While I'm here, is the proper way to set up the width and height of a new, imageless BImage this?
 
newer.width = 200;
newer.height = 100;
 
I have tried copying portions of the screen via copy(), but the image still doesn't contain anything, and doesn't change the background when I image() it in a new location...
 
Thanks.
 

--
Gary Fixler
mKoser

WWW Email
Re: can't get() into BImage
« Reply #3 on: May 22nd, 2004, 9:03pm »

woops .. sorry about that.. you are absolutely right, get() does seem to be able to fecth a pixel array.
 
i think the problem in your code is (as you are pointing at in your last post) that you never construct the 'newer' BImage object.
 
the way to do that would be:
Code:

BImage newer = new BImage(320, 240);

 
from then on you can treat it like a normal BImage.
 
(apologies for my misleading post!)
+ mikkel
« Last Edit: May 22nd, 2004, 9:04pm by mKoser »  

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
GaryFixler


Re: can't get() into BImage
« Reply #4 on: May 22nd, 2004, 11:56pm »

on May 22nd, 2004, 9:03pm, mKoser wrote:
the way to do that would be:
Code:

BImage newer = new BImage(320, 240);


Excellent, that works. Thanks very much. I caved and downloaded the newest Alpha (0069). Replicate and blend were just too cool to pass up Everything's working now. I made a very simple quadrilateral squaring tool to test out replicate:
 
http://www.garyfixler.com/squards/
 
Thanks again.
 

--
Gary Fixler
mKoser

WWW Email
Re: can't get() into BImage
« Reply #5 on: May 23rd, 2004, 12:17am »

i like it
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
Pages: 1 

« Previous topic | Next topic »