给 出高电压 低电压 和 一个周期所用的时间 一周期分四段 给出每段所用的时间 如:附件里的图
3条回答 默认 最新
- li28544071 2011-05-11 12:15关注
下面的是我自己写的一个,也不知道你的实际要求,加了点自己的想法
[code="java"]public static void main(String[] args) throws IOException {
//定义一个周期的4段时间,单位为秒,
int[] circle = new int[]{10, 15, 20, 15};
//定义1秒为5个像素点
int scale = 5;
//定义高压值、低压值,以左下角 20, -20为 0,0原点坐标,求得生成图片的宽、高
//int h_voltage = 360, l_voltage = 220;
//定义图像占用宽度,画布宽度
int width = 0, img_width = 0;
//定义图像占用高度,画布高度
int height = 360, img_height = 0;
for (int i : circle) {
width += scale * i;
}
//宽度+左右各20px的空白
img_width = width + 20 * 2;
//图片高度 + 上下各20px的空白
img_height = height + 20 * 2;
BufferedImage buffImg = new BufferedImage(img_width, img_height,BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
//将图像填充为白色
g.setColor(Color.WHITE);
g.fillRect(0, 0, img_width, img_height);
//画坐标轴
g.setColor(Color.BLACK);
g.drawLine(20, height + 20, 20, 20);
int z = 0;
for (int j = 0; j < height/10; j++) {
if(j % 5 == 0) {
g.drawString(""+(10*5*z), 0, height + 20 + 5 - j*10);
g.drawLine(20, height + 20 - j*10, 20 + 6, height + 20 - j*10);
z++;
} else {
g.drawLine(20, height + 20 - j*10, 20 + 3, height + 20 - j*10);
}
}
g.drawLine(20, height + 20, width + 20, height + 20);
g.drawString("伏", 20 - 5, 20 - 5);
g.drawString("秒", width + 20 + 5, height + 20 + 5);
//画线
g.setColor(Color.RED);
g.drawPolyline(new int[]{20, 20 + 10*scale, 20 + 10*scale, 20 + (10+15)*scale, 20 + (10+15)*scale, 20 + (10+15+20)*scale, 20 + (10+15+20)*scale, 20 + (10+15+20+15)*scale, 20 + (10+15+20+15)*scale},
new int[]{img_height-(220 + 20), img_height-(220 + 20), img_height-(360 + 20 ), img_height-(360 + 20 ), img_height-(220 + 20), img_height-(220 + 20), img_height-(360 + 20 ), img_height-(360 + 20 )}, 8);
ImageIO.write(buffImg, "jpeg", new File("C:\newImage.jpg"));
}[/code]本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1
悬赏问题
- ¥15 python的qt5界面
- ¥15 无线电能传输系统MATLAB仿真问题
- ¥50 如何用脚本实现输入法的热键设置
- ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
- ¥30 深度学习,前后端连接
- ¥15 孟德尔随机化结果不一致
- ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
- ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
- ¥15 谁有desed数据集呀
- ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100