Java后台生成图片并保存

Java后台生成图片并保存

  • 1、画板工具
  • 2、画笔工具类
  • 3、模拟数据
  • 4、测试类
  • 5、最终效果图(简易)


以波形信号为例
步骤:
①获取画板
②获取画笔
③获取坐标点

1、画板工具

import java.awt.*;

/**
 * 画板工具
 */

public class MyPanel {

    public static final int XPOINT = 100;
    public static final int YPOINT = 100;
    private double[] dataSource ; //存放数据的数组

    public MyPanel(double[] dataSource,Graphics g) {
        this.dataSource = dataSource;
        paintComponent(g);
    }

    /**
     * 生成对应图片
     * @param g
     */
    public void paintComponent(Graphics g) {
        g.setColor(Color.black);
        g.fillRect(0, 0, ImageIOHandler.WIDTH, ImageIOHandler.HEIGHT);//设置图片尺寸
        g.setColor(Color.CYAN);
        g.drawLine(XPOINT, ImageIOHandler.HEIGHT - YPOINT, XPOINT, YPOINT);//画Y轴
        g.drawLine(XPOINT,ImageIOHandler.HEIGHT/2, ImageIOHandler.WIDTH - XPOINT, ImageIOHandler.HEIGHT/2);//画X轴
        //储存曲线上所有点的x坐标
        int[] xx = new int[dataSource.length];
        //储存曲线上所有点的y坐标
        int[] yy = new int[dataSource.length];
        //对坐标数据进行赋值
        for (int i = 0; i < dataSource.length; i++) {
            xx[i] = i+XPOINT;//x轴坐标
            yy[i] = round(dataSource[i]);//y轴坐标,电压值
        }
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(Color.red);//设置曲线颜色
        g2d.drawPolyline(xx, yy, dataSource.length);//画曲线
        g.dispose();//绘制图形
    }

    //将double类型转换为int类型,并对生成曲线的位置进行校正
    public int round(double data) {
		//先转化电压值,之后再对图像位置进行调整
        return ((int)(-data*500) + ImageIOHandler.HEIGHT/2);
    }

}

2、画笔工具类

import javax.imageio.ImageIO;
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 = 5200;   //生成图片的宽度,单位是像素值
    public static final int HEIGHT = 1000;  //生成图片的高度,单位是像素值

    /**
     * 创建一个BufferedImage图片缓冲区对象并指定它宽高和类型 这样相当于创建一个画板,然后可以在上面画画
     */
    BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_BGR);

    /**
     * 要生成图片的类型,可以是JPG GIF JPEG PNG等...
     */
    final String picType = "png";

    /**
     * 成生成图片的保存路径和图片名称
     */
    final File file = new File("." + picType);

    /**
     * 通过指定参数写一个图片,并保存
     *
     * @param bi        图片缓冲流名称
     * @param picType   保存图片格式
     * @param file      保存图片的文件
     * @return boolean 如果失败返回一个布尔值
     */
    public static boolean writeImage(BufferedImage bi, String picType, File file) {
         //拿到画笔
        Graphics g = bi.getGraphics();

        //获取数据
        ECGData data = new ECGData();

        //实例化MyPanel对象,进行图片生成
        MyPanel myPanel = new MyPanel(data.getData(),g);

        boolean val = false;

        //输出为图片
        try {
            val = ImageIO.write(bi, picType, file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return val;
    }
}

3、模拟数据

/**
 * 模拟心电数据,单位mv
 */
public class ECGData {
	/**
	 * 心电数据数组
	 */
    private double[] data = {0.0130192,0.0618412,0.144839,0.247365,0.360469,0.474387,0.581796,0.676185,0.7543,0.814514,0.85764,0.878796,0.878796,0.858454,0.822651,0.773829,0.715242,0.649333,0.579354,0.509376,0.440212,0.375116,0.315716,0.261198,0.214003,0.172504,0.135888,0.104154,0.0756741,0.0512631,0.0309206,0.0170877,0.0089507,0.0040685,0,-0.0056959,-0.0138329,-0.0227836,-0.0333617,-0.0439398,-0.0553316,-0.0675371,-0.0789289,-0.0886933,-0.0968303, -0.102526,-0.106595,-0.109849,-0.109849,
		-0.105781,-0.0984577,-0.0870659,-0.0724193,-0.0545179,-0.0341754,-0.0146466,0,0.0089507,0.0113918,0.008137,0.0016274,-0.0065096,-0.0154603,-0.0227836,-0.0268521,-0.0292932,-0.0301069,-0.0317343,-0.0349891,0.0390576,-0.0423124,-0.0447535,-0.0439398,-0.040685,-0.0333617,-0.0235973,-0.0138329,-0.0065096,-0.0024411,-0.0008137,-0.0016274,-0.0065096,-0.0154603,-0.0284795,-0.0439398,-0.0610275,-0.0764878,-0.089507,-0.0984577,-0.10334,-0.106595,-0.109036,-0.111477,-0.113918,-0.117173,-0.124496,-0.135888,-0.152162,-0.171691,-0.192847,-0.211562,-0.226209,-0.236787,-0.243296,-0.244924,-0.241669,-0.234346,-0.226209,-0.219699,-0.216444,-0.216444,-0.219699,-0.227022,-0.240041,-0.255502,-0.273403,-0.290491,-0.304324,-0.311647,-0.312461,-0.306765,-0.297814,-0.285609,-0.275031,-0.268521,-0.26608,-0.266894,-0.267707,-0.268521,-0.267707,-0.262825,-0.253061,-0.238414,-0.221326,-0.205052,-0.193661,-0.187965,-0.187151,-0.187965,-0.190406,-0.192847,-0.195288,-0.197729,-0.20017,-0.20017,-0.197729,-0.192033,-0.183896,-0.171691,-0.15623,-0.139956,-0.124496,-0.112291,-0.104967,-0.104967,-0.109849,-0.116359,-0.123682,-0.131819,-0.141584,-0.149721,-0.154603,-0.15623,-0.153789,-0.149721,-0.142397,-0.135074,-0.129378,-0.129378,-0.136702,-0.148093,-0.159485,-0.166809,-0.16925,-0.166809,-0.16274,-0.158671,-0.15623,-0.154603,-0.152976,-0.152976,-0.154603,-0.157044,-0.157858,-0.15623,-0.153789,-0.149721,-0.146466,-0.143211,-0.139956,-0.141584,-0.148093,-0.157858,-0.167622,-0.174946,-0.176573,-0.173318,-0.166809,-0.15623,-0.146466,-0.136702,-0.129378,-0.124496,-0.12531,-0.129378,-0.133447,-0.138329,-0.142397,-0.142397,-0.137515,-0.126124,-0.112291,-0.101713,-0.0992714,-0.104154,-0.113104,-0.121241,-0.126937,-0.127751,-0.124496,-0.116359,-0.104154,-0.0935755,-0.0886933,-0.0903207,-0.0968303,-0.105781,-0.113918,-0.117987,
		-0.117987,-0.113918,-0.104154,-0.0911344,-0.0781152,-0.0707919,-0.0699782,-0.0707919,-0.0724193,-0.0740467,-0.0789289,-0.0911344,-0.106595,-0.122055,-0.127751,-0.122055,-0.109036,-0.0935755,-0.0805563,-0.0699782,-0.0626549,-0.0594001,-0.0594001,-0.0634686,-0.0707919,-0.0805563,-0.0919481,-0.102526,-0.106595,-0.104154,-0.0968303,-0.0886933,-0.0805563,-0.073233,-0.0667234,-0.0610275,-0.0594001,-0.0602138,-0.0634686,-0.0667234,-0.073233,-0.0805563,-0.0838111,-0.0797426,-0.0667234,-0.0496357,-0.0341754,-0.0235973,-0.0170877,-0.0130192,-0.0089507,-0.008137,-0.0113918,-0.0146466,-0.016274,-0.0138329,-0.0065096,0.0056959,0.0219699,0.0374302,0.0512631,0.0634686,0.0748604,0.0805563,0.0764878,0.0642823,0.0504494,0.0414987,0.0382439,0.0414987,0.0504494,0.0626549,0.0748604,0.0838111,0.0870659,0.0870659,0.0878796,0.0903207,0.0935755,0.0968303,0.100085,0.102526,0.10334,0.100085,0.0960166,0.0935755,0.0935755,0.0927618,0.0911344,0.0870659,0.0821837,0.0773015,0.0716056,0.0659097,0.0626549,0.0618412,0.0618412,0.0618412,0.0626549,0.0618412,0.0594001,0.0545179,0.048822,0.0431261,0.0390576,0.0366165,0.0366165,0.0390576,0.0431261,0.0504494,0.0577727,0.0634686,0.0659097,0.0675371,0.0707919,0.0756741,0.0797426,0.0821837,0.0805563,0.0764878,0.0724193,0.0691645,0.0667234,0.065096,0.0618412,0.0594001,0.0602138,0.0659097,0.0781152,0.0992714,0.132633,0.180641,0.241669,0.31002,0.377557,0.439398,0.492289,0.534601,0.564708,0.577727,0.571217,0.542738,0.497984,0.445908,0.393017,0.345823,0.308392,0.28154,0.262825,0.25062,0.241669,0.233532,0.223768,0.211562,0.198543,0.183896,0.170063,0.154603,0.138329,0.122869,0.108222,0.097644,0.089507,0.0829974,0.0781152,0.0740467,0.0699782,0.0675371,0.0642823,0.0618412,0.0602138,0.0577727,0.0553316,0.0528905,0.0504494,0.048822,0.0480083,0.0480083,0.0471946,0.0463809,0.0439398,0.0431261,0.0423124,0.0431261,0.0439398,0.0463809,0.0471946,0.0471946,0.0447535,0.0423124,0.0390576,0.0374302,0.0366165,0.0366165,0.0374302,0.0374302,0.0366165,0.0349891,0.0333617,0.0309206,0.0268521,0.0235973,0.0211562,0.0187151,0.0179014,0.0179014,0.0187151,0.0187151,0.0187151,0.0195288,0.0203425,0.0211562,0.0227836,0.0252247,
		0.0284795,0.0309206,0.0333617,0.0358028,0.0374302,0.0398713,0.0431261,0.0455672,0.048822,0.0512631,0.0528905,0.0553316,0.056959,0.0585864,0.0585864,0.0585864,0.0602138,0.0634686,0.0659097,0.0683508,0.0707919,0.073233,0.0748604,0.0756741,0.0764878,0.0756741,0.0748604,0.0748604,0.0756741,0.0781152,0.0805563,0.0821837,0.0821837,0.0805563,0.0781152,0.0748604,0.0716056,0.0691645,0.0683508,0.0667234,0.0659097,0.065096,0.0634686,0.0610275,0.0577727,0.0545179,0.0520768,0.0512631,0.0512631,0.0512631,0.0504494,0.048822,0.0463809,0.0431261,0.0398713,0.0349891,0.0301069,0.024411,0.0187151,0.0138329,0.0097644,0.0065096,0.0032548,0,-0.0032548,-0.008137,-0.0130192,-0.0170877,-0.0211562,-0.0252247,-0.0292932,-0.0333617,-0.0366165,-0.0390576,-0.0423124,-0.0471946,-0.0528905,-0.0577727,-0.0610275,-0.0626549,-0.065096,-0.0675371,-0.0707919,-0.0740467,-0.0764878,-0.0781152,-0.0781152,-0.0773015,-0.0764878,-0.0756741,-0.0764878,-0.0789289,-0.08137,-0.0838111,-0.0846248,-0.0838111,-0.08137,-0.0789289,-0.0773015,-0.0764878,-0.0764878,-0.0756741,-0.0748604,-0.0740467,-0.0724193,-0.0724193,-0.0724193,-0.073233,-0.0740467,-0.0764878,-0.0764878,-0.0756741,-0.073233,-0.0707919,-0.0691645,-0.0683508,-0.0675371,-0.0683508,-0.0691645,-0.0675371,-0.0667234,-0.065096,-0.0642823,-0.0634686,-0.0626549,-0.0610275,-0.0602138,-0.0602138,-0.0610275,-0.0634686,-0.0642823,-0.0626549,-0.0602138,-0.0585864,-0.056959,-0.0545179,-0.0520768,-0.0504494,-0.048822,-0.0480083,-0.0480083,-0.0471946,-0.0463809,-0.0447535,-0.0431261,-0.0414987,-0.0398713,-0.0374302,-0.0358028,-0.0333617,-0.0317343,-0.0292932,-0.0276658,-0.0252247,-0.0219699,-0.0179014,-0.0138329,-0.0105781,-0.0065096,-0.0016274,0.0016274,0.0048822,0.0073233,0.0089507,0.0097644,0.0089507,0.0073233,0.0065096,0.0065096,0.0065096,0.0056959,0.0040685,0.0040685,0.0048822,0.0056959,0.0073233,0.0105781,0.0154603,0.0203425,0.0235973,0.0260384,0.0276658,0.0268521,0.0252247,0.0235973,0.0219699,0.0211562,0.0195288,0.0170877,0.0146466,0.0122055,0.0105781,0.008137,0.0056959,0.0008137,-0.0040685,-0.0105781,-0.0170877,-0.0235973,-0.0301069,-0.0358028,-0.040685,-0.0455672,-0.0504494,-0.0537042,-0.0545179,-0.0545179,-0.0545179,-0.0545179,-0.0545179,-0.0553316,-0.0561453,-0.056959,-0.0577727,-0.056959,-0.056959,-0.0561453,-0.0545179,-0.0537042,-0.0528905,-0.0528905,-0.0537042,-0.0561453,-0.0577727,-0.0585864,-0.0585864,-0.0594001,-0.0626549,-0.0675371,-0.0699782,-0.0683508,-0.0594001,-0.0423124,-0.0138329,0.0268521,0.08137,0.14728,0.218885,0.289677,0.355587,0.412546,0.45974,0.491475,
		0.506121,0.499612,0.468691,0.418242,0.357214,0.297,0.246551,0.207493,0.1782,0.155417,0.135888,0.117987,0.0984577,0.0797426,0.0610275,0.0447535,0.0301069,0.016274,0.0040685,-0.0056959,-0.0154603,-0.0235973,-0.0301069,-0.0341754,-0.0374302,-0.040685,-0.0447535,-0.0496357,-0.0537042,-0.0561453,-0.056959,-0.0577727,-0.056959,-0.056959,-0.056959,-0.056959,-0.0585864,-0.0594001,-0.0618412,-0.0634686,-0.0634686,-0.0626549,-0.0618412,-0.0602138,-0.0585864,-0.056959,-0.0553316,-0.0545179,-0.0537042,-0.0528905,-0.0512631,-0.048822,-0.0455672,-0.0431261,-0.0423124,-0.0414987,-0.040685,-0.0398713,-0.0390576,-0.0382439,-0.0374302,-0.0366165,-0.0358028,-0.0333617,-0.0309206,-0.0284795,-0.0252247,-0.024411,-0.024411,-0.0252247,-0.0252247,-0.0235973,-0.0211562,-0.0187151,-0.016274,-0.0138329,-0.0130192,-0.0122055,-0.0130192,-0.0138329,-0.0146466,-0.016274,-0.0170877,-0.0170877,-0.0179014,-0.0187151,-0.0195288,-0.0211562,-0.0211562,-0.0211562,-0.0203425,-0.0179014,-0.0154603,-0.0138329,-0.0122055,-0.0122055,-0.0122055,-0.0138329,-0.0154603,-0.0170877,-0.0179014,-0.0187151,-0.0187151,-0.0179014,-0.016274,-0.0146466,-0.0122055,-0.0105781,-0.0089507,-0.008137,-0.0073233,-0.0073233,-0.008137,-0.008137,-0.0073233,-0.0048822,-0.0016274,0.0008137,0.0040685,0.0056959,0.0073233,0.0073233,0.0065096,0.0048822,0.0040685,0.0032548,0.0032548,0.0032548,0.0048822,0.0056959,0.0065096,0.0056959,0.0048822,0.0032548,0.0008137,-0.0016274,-0.0040685,-0.0073233,-0.0097644,-0.0113918,-0.0122055,-0.0130192,-0.0146466,-0.0154603,-0.016274,-0.016274,-0.0170877,-0.0195288,-0.0219699,-0.0235973,-0.024411,-0.0260384,-0.0268521,-0.0276658,-0.0276658,-0.0284795,-0.0284795,-0.0284795,-0.0292932,-0.0309206,-0.0333617,-0.0358028,-0.0366165,-0.0358028,-0.0349891,-0.0358028,-0.0366165,-0.0374302,-0.0382439,
		-0.0382439,-0.0374302,-0.0374302,-0.0374302,-0.0390576,-0.0414987,-0.0439398,-0.0447535,-0.0447535,-0.0447535,-0.0439398,-0.0439398,-0.0431261,-0.0439398,-0.0447535,-0.0463809,-0.0471946,-0.0471946,-0.0480083,-0.0480083,-0.0480083,-0.0480083,-0.0480083,-0.048822,-0.0496357,-0.0504494,-0.0520768,-0.0520768,-0.0520768,-0.0504494,-0.0480083,-0.0455672,-0.0431261,-0.0398713,-0.0366165,-0.0333617,-0.0292932,-0.024411,-0.0195288,-0.0146466,-0.0089507,-0.0032548,0.0024411,0.0065096,0.008137,0.0097644,0.0113918,0.0130192,0.0146466,0.0154603,0.016274,0.016274,0.0170877,0.0170877,0.016274,0.016274,0.016274,0.0170877,0.0195288,0.0227836,0.0252247,0.0276658,0.0292932,0.0309206,0.0333617,0.0349891,0.0358028,0.0349891,0.032548,0.0292932,0.0260384,0.0227836,0.0195288,0.016274,0.0138329,0.0113918,0.0089507,0.0056959,0,-0.0056959,-0.0122055,-0.0187151,-0.024411,-0.0284795,-0.0317343,-0.0349891,-0.0374302,-0.0382439,-0.0358028,-0.0317343,-0.0260384,-0.0179014,-0.0097644,-0.0008137,0.0056959,0.0105781,0.0138329,0.0146466,0.0138329,0.0097644,0.0040685,-0.0032548,-0.0130192,-0.0227836,-0.0341754,-0.0447535,-0.0528905,-0.0594001,-0.0634686,-0.0659097,-0.0683508,-0.0707919,-0.0716056,-0.0683508,-0.0585864,-0.0423124,-0.0170877,0.0187151,0.0675371,0.127751,0.193661,0.260384,0.323853,0.381625,0.433702,0.476828,0.506935,0.519141,0.509376,0.476828,0.427193,0.371861,0.320598,0.275844,0.2376,0.204239,0.174946,0.148907,0.12531,0.10334,0.0862522,0.0756741,0.0683508,0.0626549,0.056959,0.0504494,0.0423124,0.032548,0.0211562,0.0089507,-0.0024411,-0.0138329,-0.0235973,-0.0301069,-0.0333617,-0.032548,-0.0276658,-0.0203425,-0.0113918,-0.0040685,0,0.0016274,0.0008137,0,-0.0032548,-0.008137,-0.016274,-0.0276658,-0.0390576,-0.0496357,-0.056959,-0.0602138,-0.0577727,-0.0528905,-0.0447535,-0.0374302,-0.0309206,-0.0252247,-0.0211562,-0.0195288,-0.0195288,-0.0227836,-0.0284795,-0.0366165,-0.0439398,-0.048822,-0.0512631,-0.0512631,-0.048822,-0.0447535,-0.0414987,-0.040685,-0.0439398,-0.048822,-0.0545179,-0.0602138,-0.0634686,-0.0634686,-0.0594001,-0.0512631,-0.0414987,-0.032548,-0.0284795,-0.0301069,-0.0358028,-0.0414987,-0.0463809,-0.0496357,-0.0520768,-0.0512631,-0.0480083,-0.0414987,
		-0.032548,-0.0219699,-0.0105781,-0.0032548,0,-0.0016274,-0.0073233,-0.016274,-0.0268521,-0.0349891,-0.0390576,-0.0390576,-0.0358028,-0.0284795,-0.0203425,-0.0130192,-0.0089507,-0.0073233,-0.0065096,-0.0073233,-0.008137,-0.0065096,-0.0016274,0.0024411,0.0073233,0.0122055,0.016274,0.0195288,0.0211562,0.0203425,0.0179014,0.0146466,0.0097644,0.0065096,0.0048822,0.0024411,0.0016274,0.0040685,0.0122055,0.0235973,0.0317343,0.0333617,0.0292932,0.0219699,0.016274,0.0138329,0.0154603,0.0195288,0.0292932,0.040685,0.0528905,0.0602138,0.0626549,0.0602138,0.0545179,0.0463809,0.0390576,0.032548,0.0252247,0.0170877,0.0113918,0.0073233,0.0048822,0.0008137,-0.0040685,-0.0089507,-0.0130192,-0.0146466,-0.0122055,-0.0097644,-0.0089507,-0.0097644,-0.0113918,-0.0138329,-0.0179014,-0.0211562,-0.0219699,-0.0203425,-0.0170877,-0.0122055,-0.0073233,-0.0024411,-0.0008137,-0.0008137,-0.0008137,0,0,0,-0.0008137,0.0008137,0.0048822,0.0089507,0.0122055,0.0146466,0.0179014,0.0235973,0.0349891,0.0537042,0.0773015,0.0984577,0.110663,0.112291,0.104967,0.0927618,0.0764878,0.0520768,0.0138329,-0.0431261,-0.120428,-0.207493,-0.289677,-0.357214,-0.40685,-0.437771,-0.449976,-0.445908,-0.429634,-0.406036,-0.379998,-0.358028,-0.338499,-0.323853,-0.315716,-0.314088,-0.318157,-0.32548,-0.332803,-0.339313,-0.343381,-0.345009,-0.344195,-0.340127,-0.332803,-0.32548,-0.317343,-0.304324,-0.283981,-0.257129,-0.227836,-0.197729,-0.167622,-0.136702,-0.104154,-0.0724193,-0.0455672,-0.0276658,-0.0203425,-0.0203425,-0.0252247,-0.0284795,-0.0301069,-0.0292932,-0.0268521,-0.0227836,-0.0203425,
		-0.0179014,-0.0146466,-0.0113918,-0.0089507,-0.0097644,-0.0122055,-0.0138329,-0.0130192,-0.0113918,-0.0089507,-0.0056959,-0.0032548,-0.0024411,-0.0016274,-0.0008137,0,0,0.0016274,0.0048822,0.0073233,0.0089507,0.0097644,0.0097644,0.0122055,0.0170877,0.0252247,0.0349891,0.0447535,0.0528905,0.056959,0.0561453,0.0512631,0.0455672,0.0398713,0.0366165,0.0382439,0.0447535,0.0545179,0.0659097,0.0781152,0.0878796,0.0935755,0.097644,0.101713,0.108222,0.115545,0.122869,0.129378,0.136702,0.146466,0.157044,0.165995,0.170877,0.174132,0.1782,0.182269,0.18471,0.18471,0.183083,0.180641,0.179828,0.181455,0.187151,0.195288,0.205866,0.215631,0.225395,0.235973,0.247365,0.255502,0.25957,0.257943,0.252247,0.242483,0.232718,0.223768,0.218072,0.211562,0.204239,0.196102,0.189592,0.186337,0.183896,0.182269,0.1782,0.16925,0.15623,0.139956,0.122869,0.108222,0.0960166,0.0878796,0.0829974,0.0781152,0.0724193,0.065096,0.056959,0.0496357,0.0423124,0.0374302,0.0341754,0.0341754,0.0333617,0.0301069,0.0260384,0.0195288,0.0122055,0.0040685,-0.0016274,-0.0065096,-0.0105781,-0.0138329,-0.0170877,-0.0195288,-0.0227836,-0.0260384,-0.0284795,-0.0309206,-0.0333617,-0.0358028,-0.0374302,-0.0390576,-0.040685,-0.0414987,-0.0423124,-0.0414987,-0.040685,-0.0398713,-0.0390576,-0.0382439,-0.0374302,-0.0358028,-0.0341754,-0.0333617,-0.0317343,-0.0309206,-0.0301069,-0.0292932,-0.0292932,-0.0292932,-0.0292932,-0.0309206,-0.0333617,-0.0349891,-0.0374302,-0.040685,-0.0423124,-0.0447535,-0.0463809,-0.048822,-0.048822,-0.0471946,-0.0447535,-0.0423124,
		-0.040685,-0.0398713,-0.0398713,-0.0414987,-0.0423124,-0.0431261,-0.0439398,-0.0439398,-0.0455672,-0.0471946,-0.048822,-0.0504494,-0.0512631,-0.0520768,-0.0528905,-0.0537042,-0.0545179,-0.0545179,-0.0545179,-0.0537042,-0.0528905,-0.0528905,-0.0553316,-0.0585864,-0.0610275,-0.0626549,-0.0634686,-0.0634686,-0.0634686,-0.0618412,-0.0602138,-0.0585864,-0.056959,-0.056959,-0.0561453,-0.056959,-0.0594001,-0.0626549,-0.0659097,-0.0675371,-0.0683508,-0.0667234,-0.0626549,-0.0577727,-0.0520768,-0.0480083,-0.0431261,-0.0390576,-0.0349891,-0.0317343,-0.0292932,-0.0292932,-0.0301069,-0.0309206,-0.0309206,-0.0284795,-0.0252247,-0.0211562,-0.016274,-0.0113918,-0.0065096,-0.0024411,0,0.0008137,0,-0.0008137,-0.0040685,-0.0089507,-0.0146466,-0.0203425,-0.0268521,-0.0333617,-0.0390576,-0.0431261,-0.0447535,-0.0455672,-0.0447535,-0.0463809,-0.048822,-0.0528905,-0.0577727,-0.0626549,-0.0659097,-0.0699782,-0.0740467,-0.0805563,-0.0870659,-0.0919481,-0.0927618,-0.0878796,-0.0748604,-0.0520768,-0.0154603,0.0349891,0.0984577,0.167622,0.235159,0.297814,0.353146,0.398713,0.432888,0.45079,0.449976,0.428006,0.386508,0.333617,0.279099,0.231091,0.192847,0.164367,0.143211,0.126937,0.112291,0.0968303,0.0789289,0.0602138,
		0.0423124,0.0252247,0.0089507,-0.0048822,-0.0179014,-0.0301069,-0.040685,-0.048822,-0.0561453,-0.0610275,-0.0659097,-0.0707919,-0.0748604,-0.0781152,-0.0797426,-0.08137,-0.0829974,-0.0829974,-0.08137,-0.0789289,-0.0764878,-0.0764878,-0.0781152,-0.0797426,-0.0821837,-0.0838111,-0.0846248,-0.0846248,-0.0838111,-0.0821837,-0.0797426,-0.0781152,-0.0764878,-0.0756741,-0.0748604,-0.073233,-0.0716056,-0.0699782,-0.0691645,-0.0675371,-0.0667234,-0.0659097,-0.065096,-0.065096,-0.065096,-0.065096,-0.065096,-0.065096,-0.0634686,-0.0618412,-0.0594001,-0.0585864,-0.0577727,-0.0577727,-0.0561453,-0.0553316,-0.0545179,-0.0545179,-0.0553316,-0.0553316,-0.0528905,-0.0504494,-0.048822,-0.0463809,-0.0431261,-0.0398713,-0.0366165,-0.0341754,-0.0317343,-0.0284795,-0.0260384,-0.0235973,-0.0211562,-0.0195288,-0.0195288,-0.0195288,-0.0195288,-0.0187151,-0.0179014,-0.016274,-0.0138329,-0.0122055,-0.0105781,-0.0089507,-0.008137,-0.008137,-0.008137,-0.008137,-0.008137,-0.0073233,-0.0065096,-0.0056959,-0.0056959,-0.0056959,-0.0065096,-0.0065096,-0.0065096,-0.0056959,-0.0056959,-0.0065096,-0.008137,-0.0097644,-0.0097644,-0.008137,-0.0073233,-0.0073233,-0.0073233,-0.0056959,-0.0048822,-0.0040685,-0.0040685,-0.0048822,-0.0048822,-0.0040685,
		-0.0040685,-0.0048822,-0.0073233,-0.0097644,-0.0113918,-0.0113918,-0.0122055,-0.0130192,-0.0138329,-0.0146466,-0.0154603,-0.0170877,-0.0179014,-0.0195288,-0.0211562,-0.0211562,-0.0211562,-0.0211562,-0.0219699,-0.0227836,-0.0235973,-0.0252247,-0.0260384,-0.0268521,-0.0268521,-0.0268521,-0.0268521,-0.0276658,-0.0292932,-0.0309206,-0.0301069,-0.0276658,-0.0252247,-0.0235973,-0.0235973,-0.024411,-0.0252247,-0.0260384,-0.0276658,-0.0301069,-0.0317343,-0.0317343,-0.0309206,-0.0309206,-0.0309206,-0.0317343,-0.0333617,-0.0341754,-0.0349891,-0.0349891,-0.0358028,-0.0366165,-0.0374302,-0.0374302,-0.0366165,-0.0358028,-0.0358028,-0.0374302,-0.0390576,-0.0414987,-0.0439398,-0.0463809,-0.0480083,-0.0496357,-0.0504494,-0.0520768,-0.0512631,-0.0504494,-0.0496357,-0.048822,-0.048822,-0.0480083,-0.0480083,-0.0480083,-0.048822,-0.0504494,-0.0512631,-0.0504494,-0.048822,-0.0480083,-0.0471946,-0.0471946,-0.0463809,-0.0455672};


    public double[] getData() {
        return data;
    }
}

4、测试类

/**
 * 模拟心电图的生成
 */
public class Test {
    public static void main(String[] args) {
        ImageIOHandler image = new ImageIOHandler();
        image.writeImage(image.bi, image.picType, image.file);
    }
}

5、最终效果图(简易)

Java后台生成图片并保存_第1张图片

你可能感兴趣的:(java,保存图片)