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; } }