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

36
LINES

< > BotCompany Repo | #1006917 // newBufferedImage

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

Libraryless. Click here for Pure Java version (9267L/52K).

1  
// undefined color, seems to be all black in practice
2  
// This is without alpha?
3  
static BufferedImage newBufferedImage(int w, int h) {
4  
  ret new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
5  
}
6  
7  
ifclass RGB
8  
static BufferedImage newBufferedImage(int w, int h, RGB rgb) {
9  
  ret newBufferedImage(w, h, rgb.getColor());
10  
}
11  
endif
12  
13  
static BufferedImage newBufferedImage(int w, int h, Color color) {
14  
  BufferedImage img = newBufferedImage(w, h);
15  
  Graphics2D g = img.createGraphics();
16  
  g.setColor(or(color, Color.white));
17  
  g.fillRect(0, 0, w, h);
18  
  ret img;
19  
}
20  
21  
ifclass Pt
22  
static BufferedImage newBufferedImage(Pt p, Color color) {
23  
  ret newBufferedImage(p.x, p.y, color);
24  
}
25  
endif
26  
27  
ifclass WidthAndHeight
28  
static BufferedImage newBufferedImage(WidthAndHeight size, Color color) {
29  
  ret newBufferedImage(size.w(), size.h(), color);
30  
}
31  
endif
32  
33  
// This one is with alpha...
34  
static BufferedImage newBufferedImage(int w, int h, int[] pixels) {
35  
  ret intArrayToBufferedImage(pixels, w, h);
36  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006917
Snippet name: newBufferedImage
Eternal ID of this version: #1006917/14
Text MD5: 2cf9c9696d58e43419783df2d5df7da6
Transpilation MD5: 20bad3e80ecd33210cef214a8ee703e4
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-17 18:10:33
Source code size: 1011 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 544 / 651
Version history: 13 change(s)
Referenced in: [show references]