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

15
LINES

< > BotCompany Repo | #1025281 // intArrayToBufferedImage - note: with alpha and meta

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

Transpiled version (13072L) is out of date.

1  
// from: https://stackoverflow.com/questions/14416107/int-array-to-bufferedimage
2  
// pixels are RGB pixels
3  
static BufferedImageWithMeta intArrayToBufferedImage(int[] pixels, int w, int h default pixels.length/w) {
4  
  if (w == 0 || h == 0) null;
5  
  
6  
  int[] bitMasks = new int[]{0xFF0000, 0xFF00, 0xFF, 0xFF000000};
7  
  SinglePixelPackedSampleModel sm = new(DataBuffer.TYPE_INT, w, h, bitMasks);
8  
  DataBufferInt db = new DataBufferInt(pixels, pixels.length);
9  
  WritableRaster wr = Raster.createWritableRaster(sm, db, new Point);
10  
  ret new BufferedImageWithMeta(ColorModel.getRGBdefault(), wr, false, null);
11  
}
12  
13  
static BufferedImageWithMeta intArrayToBufferedImage(int w, int... pixels) {
14  
  ret intArrayToBufferedImage(pixels, w);
15  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, wnsclhtenguj

No comments. add comment

Snippet ID: #1025281
Snippet name: intArrayToBufferedImage - note: with alpha and meta
Eternal ID of this version: #1025281/12
Text MD5: 901b190ad648e1d181c99041cb257962
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-12 07:01:43
Source code size: 738 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 311 / 482
Version history: 11 change(s)
Referenced in: [show references]