Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

13
LINES

< > BotCompany Repo | #1033441 // byteArrayToGrayBufferedImage

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (60L/1K).

1  
static BufferedImage byteArrayToGrayBufferedImage(byte[] pixels, int w, int h) {
2  
  PixelInterleavedSampleModel sm = new(
3  
    DataBuffer.TYPE_BYTE,
4  
    w,
5  
    h,
6  
    1, // pixelStride
7  
    w, // scanlineStride,
8  
    new int[] {0} // bandOffsets
9  
  );
10  
  DataBufferByte db = new(pixels, pixels.length);
11  
  WritableRaster wr = Raster.createWritableRaster(sm, db, new Point);
12  
  ret new BufferedImage(grayColorModel(), wr, false, null);
13  
}

Author comment

Began life as a copy of #1025281

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033441
Snippet name: byteArrayToGrayBufferedImage
Eternal ID of this version: #1033441/3
Text MD5: 2cb6ece291e52aea33db84d2107565a6
Transpilation MD5: ad028867fdffeff049dd93e84f17ccd6
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-27 15:53:29
Source code size: 440 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 194
Version history: 2 change(s)
Referenced in: [show references]