Re: Improving large image drawing
From: ak (spam_at_imagero.com)
Date: 02/10/04
- Next message: ak: "Re: how to learn java"
- Previous message: oneforall-allforone: "Improving large image drawing"
- In reply to: oneforall-allforone: "Improving large image drawing"
- Next in thread: oneforall-allforone: "Re: Improving large image drawing"
- Reply: oneforall-allforone: "Re: Improving large image drawing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 10 Feb 2004 15:47:45 +0100
> I'm trying to draw a very large image with Swing.
> My input is an int array, that I would like to display as an image.
> (each int is a RGB value)
> The array is quite large, and I want to avoid creating a temporary
> image to draw to the offscreen buffer of a jpanel...
for large images you should use JAI.
another way is NOT to create one big image from array, but only part it.
something like this (simplified):
int tileSize = 200;
MemoryImageSource mis;
Image img;
public MyPanel(int w, int h, int[] pixels) {
mis = new MemoryImageSource(tileSize, tileSize , pixels, 0, w);
mis.setAnimated(true);
img = Toolkit.getDefaultToolkit().createImage(mis);
}
//for repainting you should make loop over all tiles
public void paintComponent(Graphics g) {
super.paintComponent(g);
int tile = 0;
int xTileCount = w/ tileSize;
int yTileCount = w/ tileSize;
for(int i = 0; i< xTileCount; i++) {
for(int j = 0; j < yTileCount; j++) {
int offset = j * tileSize * w + i * tileSize;
mis.newPixels(pixels, offset, <ColorModel>, offset, w);
//paint img now;
g.drawImage(img, i*tileSize, j*tileSize, null);
}
}
}
-- ____________ http://reader.imagero.com the best java image reader. "oneforall-allforone" <first.contact@netcourrier.com> schrieb im Newsbeitrag news:b490297f.0402100554.52e05df8@posting.google.com... > Hi. > > I'm trying to draw a very large image with Swing. > My input is an int array, that I would like to display as an image. > (each int is a RGB value) > The array is quite large, and I want to avoid creating a temporary > image > to draw to the offscreen buffer of a jpanel... > Here is the code I want to improve: > ----------------------------------------------------------- > final class MyPanel extends JPanel { > > private final MemoryImageSource mis; > private final FilteredImageSource fis; > private final AreaAveragingScaleFilter aas = new > AreaAveragingScaleFilter(100, 100); > > // this is the constructor for my class. > // w is the image desired width > // h is the image desired height > // pixels is a w*h array with an rgb value. > public MyPanel(int w, int h, int[] pixels) { > // MemoryImageSource is a producer that feeds each > // of it's registered consumer with values of 'pixels' > mis = new MemoryImageSource(w, h, pixels, 0, w); > } > > /** > * @param g > * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) > */ > protected void paintComponent(Graphics g) { > super.paintComponent(g); > Graphics2D g2 = (Graphics2D) g; > // The method create image creates a temporary image > // which is drawn to the offscreen buffer of this panel. > g2.drawImage(getToolkit().createImage(mis), 0, 0, Color.BLACK,null); > } > } > ----------------------------------------------------------- > > This is not optimal, since the tempo image creation leads to an > OutOfMemory when > the pixels array is big. > > To solve that problem, I would like to bypass the creation of a tempo > image. > This could be done if I had the offscreen image for the instance of > MyPanel. > I tryed using the RepaintManager, but w/o the results I hopped. > So if sbdy has any idea, I would greatly approciate.
- Next message: ak: "Re: how to learn java"
- Previous message: oneforall-allforone: "Improving large image drawing"
- In reply to: oneforall-allforone: "Improving large image drawing"
- Next in thread: oneforall-allforone: "Re: Improving large image drawing"
- Reply: oneforall-allforone: "Re: Improving large image drawing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|