需要合并图片,图片没有重叠但是上下是连接再一起的本来用的方法是:
File fileOne = new File(filePath+leftcoordinate_x+"("+i+")"+".Png");
BufferedImage ImageOne = ImageIO.read(fileOne);
int width = ImageOne.getWidth();//图片宽度
int height = ImageOne.getHeight();//图片高度
//从图片中读取RGB
int[] ImageArrayOne = new int[width*height];
ImageArrayOne = ImageOne.getRGB(0,0,width,height,ImageArrayOne,0,width);
//对第二张图片做相同的处理
int two=i+1;
File fileTwo = new File(filePath+leftcoordinate_x+"("+two+")"+".Png");
BufferedImage ImageTwo = ImageIO.read(fileTwo);
int[] ImageArrayTwo = new int[width*height];
ImageArrayTwo = ImageTwo.getRGB(0,0,width,height,ImageArrayTwo,0,width);
//对第三张图片做相同的处理
int three=i+2;
File fileThree = new File(filePath+leftcoordinate_x+"("+three+")"+".Png");
BufferedImage ImageThree = ImageIO.read(fileThree);
int[] ImageArrayThree = new int[width*height];
ImageArrayThree = ImageThree.getRGB(0,0,width,height,ImageArrayThree,0,width);
//生成新图片
int widthtwo=width+1240;
BufferedImage ImageNew = new BufferedImage(widthtwo,height,BufferedImage.TYPE_INT_RGB);
ImageNew.setRGB(0,0,width,height,ImageArrayOne,0,width);//设置左半部分的RGB
ImageNew.setRGB(623,0,width,height,ImageArrayTwo,0,width);//设置右半部分的RGB
ImageNew.setRGB(1240,0,width,height,ImageArrayThree,0,width);
File outFile = new File(filePath+leftcoordinate_x+"("+i+i+")"+".Png");
ImageIO.write(ImageNew, "png", outFile);//写图片
i=i+2;
用的是setRGB(),如上所示其需要开辟一个width*height大小的空间,所以这就限制了合成图片的数量,但现在所要达到的目的是大量图片的合成
所以不能上面所说的方法,经导师提示可以文件到文件存储,不经过大内存,因为存储的是32RGB的位图文件,读取一个文件然后篡改BMP的都文件信息
然后用流的方式存入文件中,但不关闭流,接着读入下一个文件还向刚才那个文件中存储只是去掉了头文件,直到把所用文件都存完,才关闭流,但是我不会实现
有高手给个类似范例,让小弟我参考一下。就是将多个BMP文件以追加的方式存到一个BMP文件中。
File fileOne = new File(filePath+leftcoordinate_x+"("+i+")"+".Png");
BufferedImage ImageOne = ImageIO.read(fileOne);
int width = ImageOne.getWidth();//图片宽度
int height = ImageOne.getHeight();//图片高度
//从图片中读取RGB
int[] ImageArrayOne = new int[width*height];
ImageArrayOne = ImageOne.getRGB(0,0,width,height,ImageArrayOne,0,width);
//对第二张图片做相同的处理
int two=i+1;
File fileTwo = new File(filePath+leftcoordinate_x+"("+two+")"+".Png");
BufferedImage ImageTwo = ImageIO.read(fileTwo);
int[] ImageArrayTwo = new int[width*height];
ImageArrayTwo = ImageTwo.getRGB(0,0,width,height,ImageArrayTwo,0,width);
//对第三张图片做相同的处理
int three=i+2;
File fileThree = new File(filePath+leftcoordinate_x+"("+three+")"+".Png");
BufferedImage ImageThree = ImageIO.read(fileThree);
int[] ImageArrayThree = new int[width*height];
ImageArrayThree = ImageThree.getRGB(0,0,width,height,ImageArrayThree,0,width);
//生成新图片
int widthtwo=width+1240;
BufferedImage ImageNew = new BufferedImage(widthtwo,height,BufferedImage.TYPE_INT_RGB);
ImageNew.setRGB(0,0,width,height,ImageArrayOne,0,width);//设置左半部分的RGB
ImageNew.setRGB(623,0,width,height,ImageArrayTwo,0,width);//设置右半部分的RGB
ImageNew.setRGB(1240,0,width,height,ImageArrayThree,0,width);
File outFile = new File(filePath+leftcoordinate_x+"("+i+i+")"+".Png");
ImageIO.write(ImageNew, "png", outFile);//写图片
i=i+2;
用的是setRGB(),如上所示其需要开辟一个width*height大小的空间,所以这就限制了合成图片的数量,但现在所要达到的目的是大量图片的合成
所以不能上面所说的方法,经导师提示可以文件到文件存储,不经过大内存,因为存储的是32RGB的位图文件,读取一个文件然后篡改BMP的都文件信息
然后用流的方式存入文件中,但不关闭流,接着读入下一个文件还向刚才那个文件中存储只是去掉了头文件,直到把所用文件都存完,才关闭流,但是我不会实现
有高手给个类似范例,让小弟我参考一下。就是将多个BMP文件以追加的方式存到一个BMP文件中。
解决方案 »
- 请问一下这道题,java的
- jdk源码中问题
- 如何从指定路径开始创建JTree?
- JUnit 对DAO数据存储问题?
- 跪求高手一览:生成表格样式的图片其字段的内容不确定导致格式无法完美定位
- 来拿分了~~我想做个1到1000之间偶数的总和,奇数的总和,不知道该怎么做了。高手赐教
- 为什么我的rmi 类文件编译通过以后 执行rmic命令 报 找不到类的错误呢
- 新手编译错误提示求教!!
- jvm和jre的区别?(进者有分,除非额满)
- 在www.sun.com.cn下载的jade是个setup.class文件,怎么用?
- 请发一份有STRUTS类的JDK文档给我吧,谢谢
- HttpServletRequest这个类有什么用途?
2 读取文件会吗?
3 新建一个文件会吗?
4 OK,新建一个文件,
5 然后打开第一个图片
6 读取数据并写入新建的文件
7 关闭第一个图片
8 打开第二个图片
9 读取前面的XXX个数据,并抛弃,具体多少,你自己去找,一般是512、256个吧
10 继续读取并写入新建的文件
11 关闭第二个文件
12 关闭新建的文件
http://topic.csdn.net/u/20080519/20/d73a3fb8-8604-4ea7-8de0-23418faed65e.html
这种效果。
能说的稍微再具体点吗?例如【6 读取数据并写入新建的文件 】以什么样的方式读入BMP文件就是以什么样的方式把其存入内存
还是要这样读 File fileThree = new File(filePath+leftcoordinate_x+"("+three+")"+".bmp");
BufferedImage ImageThree = ImageIO.read(fileThree);
int[] ImageArrayThree = new int[width*height];
ImageArrayThree = ImageThree.getRGB(0,0,width,height,ImageArrayThree,0,width); ?
还有以什么样的方式写入文件呢,又什么writer方法读入呢?
我老师的意思是这样的:篡改第一个文件的信息,把文件大小改成了合成后图片的大小。
int LB = ((width*3+3)/4)*4;
int bsize = 54+height*LB;
//篡改BMP头文件信息
ImageArrayOne[2] = bsize& 0xff;
ImageArrayOne[3] = (bsize>>8) & 0xff;
ImageArrayOne[4] = (bsize>>16) & 0xfff;
ImageArrayOne[5] = (bsize>>24) & 0xff; ImageArrayOne[18] = width& x0ff;//更改BMP的width
ImageArrayOne[19] = (width>>8) & 0xff;;
ImageArrayOne[20] = (width>>16) &0xff;
ImageArrayOne[21] = (width>>24) & 0xff; ImageArrayOne[22] = height& x0ff;
ImageArrayOne[23] = (height>>8) & 0xff;
ImageArrayOne[24] = (height>>16) & 0xff;
ImageArrayOne[25] = (height>>24) & 0xff; ImageArrayOne[34] = height*bsize;
ImageArrayOne[]数组是存储BMP信息的数组。怎么样读入后续文件,还有BMP文件头是54字节。to caoyinghui1986:
两张图片没有重合的,就比方说你的1.jpg 和2.jpg 两个一样大小,2.jpg要紧接着1.jpg,在纵方向两个是相连的,但是却没有一点重合的。
可以用java直接调用命令行
也可以用imagemagick的java包装类
jmagick 如果像用baidu一下
作图功能比java强大多