-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadIO.java
More file actions
73 lines (65 loc) · 2.42 KB
/
Copy pathReadIO.java
File metadata and controls
73 lines (65 loc) · 2.42 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
package cn.edu.ustc.aaron.encoder;
import javax.imageio.ImageIO;
import javax.imageio.IIOException;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.ImageReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.awt.image.BufferedImage;
public class ReadIO {
// public void readBmp() {
// File f;
// try {
// f = new File("E:\\JavaWorkSpace\\PsvdProject\\bmp\\00005.bmp");
// } catch (IIOException e) {
// e.printStackTrace();
// }
// BufferedImage bi = ImageIO.read(f);
// File wf = new File("E:\\JavaWorkSpace\\PsvdProject\\w05.bmp");
// ImageIO.write(bi, "bmp", wf);
// }
public static void main(String[] args) {
File f = new File("E:\\JavaWorkSpace\\PsvdProject\\bmp\\00005.bmp");
if (f == null) {
System.out.println("f==null");
}
else
{
System.out.println(f);
}
try{
BufferedImage bi = ImageIO.read(f);
System.out.println(bi.getHeight()+", width: " + bi.getWidth());
} catch (IOException e) {
System.out.println("can't open file" + f);
}
try{
BufferedImage bi = ImageIO.read(f);
File wf = new File("E:\\JavaWorkSpace\\PsvdProject\\bmp\\5w.jpg");
ImageIO.write(bi, "jpg", wf);
} catch (IOException e) {
System.out.println("can't write file" + f);
}
// File f = new File("bmp\\00005.bmp");
// ImageInputStream iis = null;
// try {
// iis = ImageIO.createImageInputStream(f);
// } catch (IIOException iioe1) {
// System.out.println("Unable to create an input stream.");
// return;
// }
// Iterator readers = ImageIO.getImageReadersByFormatName("bmp");
// ImageReader reader = (ImageReader) readers.next();
// reader.setInput(iis, true);
// try {
// reader.read(0, param);
// } catch (IIOException iioe2) {
// System.out.println("An error occured during reading: " + iioe2.getMessage());
// Throwable t = iioe2.getCause();
// if ((t != null) && (t instanceof IOException)) {
// System. out.println("Cause by IOException: " + t.getMessage());
// }
// }
}
}