-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimg.java
More file actions
116 lines (91 loc) · 3.13 KB
/
img.java
File metadata and controls
116 lines (91 loc) · 3.13 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package utilerias;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javafx.embed.swing.SwingFXUtils;
/**
*
* @author Master
*/
public class img {
public InputStream getBinary(String path){
FileInputStream iStr = null;
try{
File image = new File(path);
iStr = new FileInputStream(image);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return (InputStream)iStr;
}
public InputStream getBinary(Image img){
InputStream is = null;
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write((RenderedImage)img, "jpg", baos);
is = new ByteArrayInputStream(baos.toByteArray());
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return is;
}
public InputStream getBinary(javafx.scene.image.Image img){
InputStream is = null;
try{
BufferedImage bi = SwingFXUtils.fromFXImage(img, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bi, "jpg", baos);
is = new ByteArrayInputStream(baos.toByteArray());
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return is;
}
public javafx.scene.image.Image getImage(InputStream is){
javafx.scene.image.Image i = null;
try{
BufferedImage image = ImageIO.read(is);
i = SwingFXUtils.toFXImage(image,null);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return i;
}
public javafx.scene.image.Image getImage(byte [] arr){
javafx.scene.image.Image i = null;
try{
InputStream is = new ByteArrayInputStream(arr);
BufferedImage image = ImageIO.read(is);
i = SwingFXUtils.toFXImage(image,null);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return i;
}
public Image getImage(InputStream is, boolean x){
Image i = null;
try{
i = ImageIO.read(is);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return i;
}
}