1.编写一个图形界面程序,显示PNG(Portable Network Graphics)格式的图片。
2.给定四幅PNG格式的图片文件,编写程序,将其合并生成一幅大的PNG格式的图片文件,并能够显示。3. 编写程序,将拼接好的图片进行反色,并向右旋转90度, 并显示。
给点思路,我都不知道从哪下手,去看什么书。
谢了~
2.给定四幅PNG格式的图片文件,编写程序,将其合并生成一幅大的PNG格式的图片文件,并能够显示。3. 编写程序,将拼接好的图片进行反色,并向右旋转90度, 并显示。
给点思路,我都不知道从哪下手,去看什么书。
谢了~
记得曾经见过一个类似的,看看能不能找到。。
package test;import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;public class ImageTest { public ImageTest() {} public static void main(String[] args) {
try {
ImageTest test = new ImageTest();
test.ImageTset();
} catch (Exception e) {
System.out.print(e);
}
} public void ImageTset() throws Exception {
File _file1 = new File("E:\\qq\\1.gif");
File _file2 = new File("E:\\qq\\2.gif");
File _file3 = new File("E:\\qq\\3.gif");
File file2 = new File("E:\\qq\\newfile0.gif");
FileOutputStream fos = new FileOutputStream(file2, false);
String sfile[] = { "E:\\qq\\1.gif", "E:\\qq\\2.gif", "E:\\qq\\3.gif" };
try {
for (int i = 0; i <= sfile.length; i++) {
byte[] image = null;
File file = new File(sfile[i]);
FileInputStream fin = new FileInputStream(file);
image = new byte[fin.available()];
fin.read(image);
System.out.println(file.getPath() + "..." + image);
fos.write(image);
}
fos.close();
} catch (Exception e) {
System.out.print("........." + e);
}
//AnimatedGifEncoder e = new AnimatedGifEncoder();
//读入文件
Image src = javax.imageio.ImageIO.read(_file1);//构造Image对象
Image src2 = javax.imageio.ImageIO.read(_file2);
Image src3 = javax.imageio.ImageIO.read(_file3);
int width = src.getWidth(null);//得到源图宽
int height = src.getHeight(null);//得到源图长 BufferedImage tag = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
//tag.getGraphics().setClip(0, 0, width, height);
//tag.getGraphics().drawImage(src,0,0,width,height,null);//绘制缩小后的图
//tag.getGraphics().drawImage(src2,0,0,width,height,null);//绘制缩小后的图
//tag.getGraphics().drawImage(src3,0,0,width,height,null);//绘制缩小后的图
FileOutputStream out = new FileOutputStream("E:\\qq\\newfile3.jpeg");//输出到文件流
Graphics g = tag.createGraphics();
g.fillRect(0, 0, width, height);
g.setClip(0, 0, width, height);
g.drawImage(src, 0, 0, width, height, null);
g.drawImage(src2, 0, 0, width, height, null);
g.drawImage(src3, 0, 0, width, height, null);
g.dispose();
System.out.print(g.getColor());
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);//近JPEG编码
System.out.print(width + "*" + height);
out.close();
}
}
就是先练习一下如何读取和写入png文件,要会读取象素和写入象素
然后读取4个png,然后新建一个大的图片,把象素描上去
很老了一个贴子