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)
   BImage resize
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: BImage resize  (Read 366 times)
cc

Email
BImage resize
« on: Nov 20th, 2004, 10:27pm »

I can't seem to resize a BImage after it has been allocated. More specifically, I would like to resize an array of BImages, but I can't even find how to do it with one?
 
BImage[] imageset;
imageset = new BImage[IMG_COUNT];
for (int i=0; i < IMG_COUNT; i++)
  imageset[i].resize ( nx, ny);  //
 
Am I missing something, or does this feature not exist yet?
 
Rama
 
fjen

WWW
Re: BImage resize
« Reply #1 on: Nov 20th, 2004, 11:09pm »

if it's not in the reference the most likely it's not there ... but sometimes there are hidden features like BGraphics:
 
Code:

BImage[] imageset;  
imageset = new BImage[IMG_COUNT];
for (int i=0; i < IMG_COUNT; i++)
{
  BGraphics resized = new BGraphics(nx, ny); // new width, height
  resized.format = RGBA;  // needed due to a bug
  resized.image( imageset[i], 0, 0, nx, ny );  //draw the image scaled
  imageset[i] = new BImage(resized);  //put it back into the array
}

 
/F
 
cc

Email
Re: BImage resize
« Reply #2 on: Nov 20th, 2004, 11:59pm »

This doesn't seem to work for me. I get the following error when I try the code above: "No applicable overload was found for a constructor of type "BImage". Perhaps you wanted the overloaded version 'BImage(java.awt.Image $1);' instead?".
 
Seems like a 'type cast' issue, but I don't know how I would do this in Processing. Perhaps I am missing something.
 
fjen

WWW
Re: BImage resize
« Reply #3 on: Nov 21st, 2004, 3:50pm »

right. i thought there was a constructor using BImage.
then just do:
 
imageset[i] = ( (BImage)resized ).copy();
 
btw: if all you images are same size you might consider moving the first two lines out of (before) the for-loop ...
 
/F
 
TomC

WWW
Re: BImage resize
« Reply #4 on: Nov 21st, 2004, 5:34pm »

I don't think you need to cast a BGraphics to BImage in order to call copy(), because the return type is what matters and it returns a BImage.
 
Another way to do this is with replicate().  The following code loads an image and makes a 40x30 thumbnail of it.
 
Code:

 
BImage source = loadImage("whatever.jpg");
 
BImage thumb = new BImage(40,30);
thumb.replicate(source,0,0,source.width-1,source.height-1,0,0,thumb.widt h-1,thumb.height-1);
 

 
(The '-1' bits are because replicate asks for the coordinates of the area to copy, not the width and height... I think this might/should change in the future to match the semantics of image, rect, etc. because it's not very intuitive - I should probably check with toxi that I got it right.)
 
On update: not sure about those -1's.  The documentation suggests one thing, and the actual behaviour suggests another... anyone know the source and care to clarify?
 
« Last Edit: Nov 21st, 2004, 5:39pm by TomC »  
fjen

WWW
Re: BImage resize
« Reply #5 on: Nov 21st, 2004, 6:03pm »

yeah, i know about the return type. just wanted to make sure that in case BGraphics overloads copy (which it doesn't) you still get a BImage ...
 
i don't know about replicate() in BImage ... i think it will be replaced in megabucket.
 
 
/F
« Last Edit: Nov 21st, 2004, 6:04pm by fjen »  
TomC

WWW
Re: BImage resize
« Reply #6 on: Nov 21st, 2004, 6:58pm »

on Nov 21st, 2004, 6:03pm, fjen wrote:
yeah, i know about the return type. just wanted to make sure that in case BGraphics overloads copy (which it doesn't) you still get a BImage ...

 
I see.  I think you have a couple of things mixed up then:
 
Firstly, because BGraphics extends BImage it couldn't have a function called copy which had a different return type to copy in BImage.
 
Secondly, I don't know for sure but I don't think there's any way to use BImage's definition of copy from a BGraphics instance.  I don't think the way you did it would alter the behaviour.  Try the following:
 
Code:

 
class MyImage {
  public MyImage copy() {
    println("MyImage.copy()");
    return new MyImage();
  }
}
 
class MyGraphics extends MyImage {
  public MyImage copy() {
    println("MyGraphics.copy()");
    return new MyGraphics();
  }
}
 
void setup() {
  size(100,100);
}
 
void draw() {
  MyImage img = new MyImage();
  MyImage temp = img.copy();
   
  MyGraphics gfx = new MyGraphics();
  temp = gfx.copy();
   
  temp = ((MyImage)gfx).copy();
 
}
 

 
You should get:
 
Code:

 
MyImage.copy()
MyGraphics.copy()
MyGraphics.copy()
 

 
 
fjen

WWW
Re: BImage resize
« Reply #7 on: Nov 21st, 2004, 7:29pm »

i see ... and it makes sense.
 
i guess this leaves room to do some refresh on my fuzzy java-knowledge today ...
 
thanks!
/F
 
Pages: 1 

« Previous topic | Next topic »