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


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

Re: BufferedImage and int[] array

Newsgroups comp.lang.java.programmer
Date 2017-04-21 10:41 -0700
References <5a1d0bab-5ae7-45a1-9c8f-344183ed48ba@googlegroups.com> <4f6d8eef-73e3-45f6-94fc-4ccb530ddd8c@googlegroups.com> <0f806bdc-aa93-4897-bb9f-8373ffd16175@googlegroups.com>
Message-ID <903d6ec5-ab8e-4e87-9581-13ff803bf461@googlegroups.com> (permalink)
Subject Re: BufferedImage and int[] array
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


On Friday, April 21, 2017 at 12:03:19 PM UTC-4, Rick C. Hodgin wrote:
> That apparently works when you have a 4-byte color depth, but if it's
> not 4-bytes (32-bit) it doesn't work.  That's understandable, so I
> need to know how to convert whatever format is loaded with the
> IoImage.read() to then create a BufferedImage that is in 4-byte form?
> 
> Thank you,
> Rick C. Hodgin

Here again it would help if you have some source code that's not working to debug.  I'm going to guess the image bytes you have are file bytes.
          
          final byte[] contents;
          InputStream myFileInputStream;
          File myImgFile = new File("c:/image.png");
          myFileInputStream = new FileInputStream(myImgFile);
          contents = new byte[myFileInputStream.available()];
          myFileInputStream.read(contents);
          myFileInputStream.close();

Then you can get an image from those bytes.

          ByteArrayInputStream myByteArrayInputStream;
          BufferedImage myBufferedImage = null;
          myByteArrayInputStream = new ByteArrayInputStream(contents);
          final MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(myByteArrayInputStream);
          myBufferedImage = ImageIO.read(mciis);

Then you can grab the int[] reference.
          int[] pixels = ((DataBufferInt)myBufferedImage.getRaster().getDataBuffer()).getData(); 

There is no casting the byte[].  I think that stackoverflow you linked explains the int[] well.  What else are you missing?

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next 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