Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36524

Re: BufferedImage and int[] array

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: BufferedImage and int[] array
Date 2017-04-24 11:25 -0500
Organization A noiseless patient Spider
Message-ID <odl8oh$9ku$1@dont-email.me> (permalink)
References <5a1d0bab-5ae7-45a1-9c8f-344183ed48ba@googlegroups.com> <odg05k$e1f$1@dont-email.me> <0ed9258a-3395-4440-8793-b46427df4664@googlegroups.com>

Show all headers | View raw


On 4/24/2017 10:17, Rick C. Hodgin wrote:
> Would it be possible to do this?
>
> import java.awt.*;
> import java.awt.image.*;
> import java.io.*;
> import javax.imageio.*;
>
> public class test6 {
>      public static void main(String... args) throws Exception {
>          RescaleOp op = new RescaleOp(-1.0f,255f,null);
>          BufferedImage img =
>           new BufferedImage(640,480,BufferedImage.TYPE_INT_RGB);
>          Graphics2D g = img.createGraphics();
>          g.setColor(Color.RED);
>          g.fillRect(0,0,213,480);
>          g.setColor(Color.GREEN);
>          g.fillRect(214,0,214,480);
>          g.setColor(Color.BLUE);
>          g.fillRect(428,0,213,480);
>          g.dispose();
>
> ===> Something like this, where the input img bits are updated directly:
>          img = op.filter(img,null);
>          // Maintain img, now altered, as it was before
>      }
> }
>
> That's what I'm trying to do with my algorithms.  Receive an existing
> image and then process it in some way which directly updates its bits
> without copying or creating a new image for output in the process.
>
> Thank you,
> Rick C. Hodgin

Yes however I'm pretty sure that if you use null as the second argument 
to BufferredImageOp.filter that it creates a new BufferedImage.  I think 
if you put the same reference in the call to filter it is the same image 
modified in place.

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class test6 {
     public static void main(String... args) throws Exception {
         BufferedImage img =
          new BufferedImage(640,480,BufferedImage.TYPE_INT_RGB);
         Graphics2D g = img.createGraphics();
         g.setColor(Color.RED);
         g.fillRect(0,0,213,480);
         g.setColor(Color.GREEN);
         g.fillRect(213,0,214,480);
         g.setColor(Color.BLUE);
         g.fillRect(427,0,213,480);
         g.dispose();

         RescaleOp op = new RescaleOp(-1.0f,255f,null);
         BufferedImage gmi = op.filter(img,img);
         System.out.println(gmi.equals(img));
     }
}

In this case the output is true.  If you put null in the second argument 
the output is false.  I don't know if it is any faster, the cost of 
creating a small BufferedImage is not that great.


-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-21 08:28 -0700
  Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-21 08:54 -0700
    Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-21 09:03 -0700
      Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-21 10:41 -0700
        Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-21 10:46 -0700
        Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-21 11:13 -0700
          Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-21 12:12 -0700
          Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-21 13:24 -0700
            Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-21 13:37 -0700
              Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-21 13:40 -0700
              Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-21 13:54 -0700
                Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-21 13:59 -0700
              Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-21 13:58 -0700
                Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-21 14:06 -0700
  Re: BufferedImage and int[] array Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-04-22 11:28 -0500
    Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-24 07:33 -0700
      Re: BufferedImage and int[] array Eric Douglas <e.d.programmer@gmail.com> - 2017-04-24 08:04 -0700
    Re: BufferedImage and int[] array "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-24 08:17 -0700
      Re: BufferedImage and int[] array Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-04-24 11:25 -0500

csiph-web