-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJSImage.java
More file actions
70 lines (60 loc) · 1.78 KB
/
Copy pathJSImage.java
File metadata and controls
70 lines (60 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package swingjs;
import javajs.util.Base64;
import jsjava.awt.image.BufferedImage;
import swingjs.api.DOMNode;
/**
* A JavaScript version of BufferedImage.
*
* Created from JSImagekit when creating an image
* from byte[] or from loading a GIF, PNG, or JPG image.
*
* The difference is that when from byte[] data, the
* field _pix will be initialized to the raster data,
* but _imgNode will be null; when an image is used, then
* _pix will be there, but it will not be populated unless
* a call to setRGB is made. Until then, JSGraphics2D.drawImage will
* simply use the image itself. But the _pix data will still
* be available as _imgNode.pbuf32.
*
* Only integer raster data RGB and ARGB have been implemented.
*
* useful states:
*
* _domNode != null ==> came from an image node (image file)
* _canvas != null ==> an image has been created from raster data
*
*
*
*
* @author Bob Hanson
*
*/
public class JSImage extends BufferedImage {
// a BufferedImage in name only, actually;
// TODO: implement simple ColorModel and Raster
public String src;
public JSImage(int[] argb, int width, int height, String src) {
super(width, height, TYPE_INT_ARGB);
this.src = src;
_pix = argb;
}
/**
* Use HTML5 to load PNG, JPG, or GIF image in order to extract its pixels
*
* @param b
* @param type
*/
@SuppressWarnings("unused")
public void getDOMImage(byte[] b, String type) {
String dataurl = "data:image/" + type + ";base64," + Base64.getBase64(b).toString();
DOMNode img = null;
/**
* @j2sNative
* img = new Image(this.width, this.height);
* //if (this.callback) img.onload = this.callback;
* img.src = dataurl;
*/
{}
_imgNode = img;
}
}