zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
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
package DrawJPG;
import javax.imageio.ImageIO;
 
import PbuliClass.Leds;
 
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
 
/**
 * ½«ÐĵçÊý¾ÝÔÚºǫ́Êä³öΪpng¸ñʽ
 */
public class ImageIOHandler {
 
    //Éú³ÉͼƬµÄ¿í¶È,µ¥Î»ÊÇÏñËØÖµ
    public static final int WIDTH =Integer.parseInt(Leds.get_tb_led().getLed_w()); 
    
    //Éú³ÉͼƬµÄ¸ß¶È,µ¥Î»ÊÇÏñËØÖµ
    public static final int HEIGHT =Integer.parseInt(Leds.get_tb_led().getLed_h());  
 
    /**
     * ´´½¨Ò»¸öBufferedImageͼƬ»º³åÇø¶ÔÏó²¢Ö¸¶¨Ëü¿í¸ßºÍÀàÐÍ ÕâÑùÏ൱ÓÚ´´½¨Ò»¸ö»­°å£¬È»ºó¿ÉÒÔÔÚÉÏÃæ»­»­
     */
    public BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_BGR);
 
    /**
     * ÒªÉú³ÉͼƬµÄÀàÐÍ,¿ÉÒÔÊÇJPG GIF JPEG PNGµÈ...
     */
    public  String picType = "png";
 
    /**
     * ³ÉÉú³ÉͼƬµÄ±£´æÂ·¾¶ºÍͼƬÃû³Æ
     */
    final File file = new File("." + picType);
 
    /**
     * Í¨¹ýÖ¸¶¨²ÎÊýдһ¸öͼƬ,²¢±£´æ
     *
     * @param bi        Í¼Æ¬»º³åÁ÷Ãû³Æ
     * @param picType   ±£´æÍ¼Æ¬¸ñʽ
     * @param file      ±£´æÍ¼Æ¬µÄÎļþ
     * @return boolean Èç¹ûʧ°Ü·µ»ØÒ»¸ö²¼¶ûÖµ
     */
    @SuppressWarnings("unused")
    public static boolean writeImage(BufferedImage bi, String picType, File file) {
        //Äõ½»­±Ê
        Graphics g = bi.getGraphics();
 
        //»ñÈ¡Êý¾Ý
        ECGData data = new ECGData();
 
        //ʵÀý»¯MyPanel¶ÔÏó,½øÐÐͼƬÉú³É
        MyPanel2 myPanel = new MyPanel2(g);
 
        boolean val = false;
 
        //Êä³öΪͼƬ
        try {
            val = ImageIO.write(bi, picType, file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return val;
    }
}