import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ZHBingo
*/
public class Graphics4 {
public static void main(String[] args) {
try{
int color;
BufferedImage image = ImageIO.read(new File ("image/Undefined.jpg"));//读取一个待处理图像
BufferedImage blank = ImageIO.read(new File ("image/blank.jpg"));//读取一个空白图像
//定义变换矩阵
double[][] matrix = new double[3][3];
//旋转参数
double angle = Math.PI * 0 ;//旋转角度
//平移参数
double moveX = 0;//X轴平移长度
double moveY = 0;//Y轴平移长度
//缩放、旋转、对称、错切参数
double a = -1;
double b = 0;
double d = 0;
double e = 1;
//初始化矩阵
matrix[0][0] = a * Math.cos(angle); matrix[0][1] = d * Math.sin(angle); matrix[0][2] = 0;
matrix[1][0] = - b * Math.sin(angle); matrix[1][1] = e * Math.cos(angle); matrix[1][2] = 0;
matrix[2][0] = moveX; matrix[2][1] = moveY; matrix[2][2] = 1;
for(int j = 0;j < HEIGHT;j ++)
for(int i =0;i < WIDTH; i++){
color = image.getRGB(i, j);
blank.setRGB( (int)( matrix[0][0] * i + matrix[1][0] * j + matrix[2][0] + BLANK_WIDTH / 2),
(int)( matrix[0][1] * i + matrix[1][1] * j + matrix[2][1] + BLANK_HEIGHT / 2),
color );
}
//绘制坐标系
for(int x = 0; x < BLANK_WIDTH; x++){
blank.setRGB(x, BLANK_HEIGHT / 2, 0x000000);
}
for(int y = 0; y < BLANK_HEIGHT; y++){
blank.setRGB(BLANK_WIDTH / 2, y, 0x000000);
}
//绘制坐标轴箭头
for(int arrow = 1; arrow < 100; arrow++){
blank.setRGB(BLANK_WIDTH / 2 - arrow, BLANK_HEIGHT - arrow, 0x000000);
blank.setRGB(BLANK_WIDTH / 2 + arrow, BLANK_HEIGHT - arrow, 0x000000);
blank.setRGB(BLANK_WIDTH - arrow, BLANK_HEIGHT / 2 - arrow, 0x000000);
blank.setRGB(BLANK_WIDTH - arrow, BLANK_HEIGHT / 2 + arrow, 0x000000);
}
//输出已经填充好的图形
Util.creatNewImage(blank,BLANK_WIDTH,BLANK_HEIGHT,0,0,"JPG","image/变换后的图形.jpg");
}catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR!", 0) ;
}
}
//待处理图像的宽和高
public static final int WIDTH = 800;
public static final int HEIGHT = 600;
//画板的宽和高
public static final int BLANK_WIDTH = 4000;
public static final int BLANK_HEIGHT = 4000;
}
/*
* 功能类
*/
class Util{
//生成图像
public static void creatNewImage(BufferedImage image,
int height,
int width,
int leftTopX,
int leftTopY,
String type,
String imageName) throws Exception{
BufferedImage img = new BufferedImage( height,width, BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.drawImage(image, -leftTopX, -leftTopY, null);
ImageIO.write(img, type, new File(imageName));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java 图形学 5种画图方式
共75个文件
xml:20个
properties:15个
class:15个
5星 · 超过95%的资源 需积分: 9 9 下载量 154 浏览量
2011-08-17
20:30:18
上传
评论
收藏 203KB RAR 举报
温馨提示
中点画线 Bresenham画线 填充算法 图形矩阵变换 Bezier画曲线
资源推荐
资源详情
资源评论
收起资源包目录
图形学.rar (75个子文件)
图形学
Graphics3
image
填充后的图形.jpg 8KB
Undefined.jpg 8KB
test
build.xml 4KB
manifest.mf 85B
src
Graphics3.java 3KB
nbproject
build-impl.xml 42KB
private
private.xml 211B
private.properties 184B
project.xml 517B
genfiles.properties 475B
project.properties 2KB
build
classes
Util.class 1KB
.netbeans_automatic_build 0B
Graphics3.rs 37B
Graphics3.class 2KB
DrawComponent.class 2KB
Graphics4
image
变换后的图形.jpg 299KB
blank.jpg 245KB
Undefined.jpg 89KB
test
build.xml 4KB
manifest.mf 85B
src
Graphics4.java 4KB
nbproject
build-impl.xml 42KB
private
private.xml 371B
private.properties 184B
project.xml 517B
genfiles.properties 475B
project.properties 2KB
build
classes
Util.class 1KB
Graphics4.rs 17B
.netbeans_automatic_build 0B
Graphics4.class 2KB
Graphics5
test
build.xml 4KB
manifest.mf 85B
src
Graphics5.java 3KB
nbproject
build-impl.xml 42KB
private
private.xml 211B
private.properties 184B
project.xml 517B
genfiles.properties 475B
project.properties 2KB
build
classes
Util.class 2KB
.netbeans_automatic_build 0B
Graphics5.class 604B
DrawComponent.class 2KB
Graphics5.rs 43B
DrawFrame.class 618B
Graphics2
test
build.xml 4KB
manifest.mf 85B
src
Graphics2.java 2KB
nbproject
build-impl.xml 42KB
private
private.xml 211B
private.properties 184B
project.xml 517B
genfiles.properties 475B
project.properties 2KB
build
classes
.netbeans_automatic_build 0B
Graphics2.class 604B
Graphics2.rs 37B
DrawComponent.class 2KB
DrawFrame.class 618B
Graphics1
test
build.xml 4KB
manifest.mf 85B
src
Graphics1.java 3KB
nbproject
build-impl.xml 42KB
private
private.xml 340B
private.properties 184B
project.xml 517B
genfiles.properties 475B
project.properties 2KB
build
classes
DrawComponent1.class 2KB
Graphics1.class 604B
.netbeans_automatic_build 0B
Graphics1.rs 38B
DrawFrame.class 617B
共 75 条
- 1
资源评论
- shenwenxiu10092012-08-31很好,很基础适合初学者
- Allolly2014-02-24都可以运行,就是比较简单,适合入门
zcm8987872
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功