1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
//import applicationDispatcher.bin.Application;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Merger2 {
private BufferedImage completeImg;
private int width;
private int height;
public Merger2(int width, int height){
completeImg = new BufferedImage(width,height,5);
this.height = height;
this.width = width;
}
public synchronized void addFragment(File f, int startX, int startY, int endX, int endY){
BufferedImage fragment = null;
try
{
System.out.println(f.toString());
fragment = ImageIO.read(f);
}
catch (IOException e) { e.printStackTrace();}
int RGB [] =
fragment.getRGB(startX, startY, endX - startX, endY - startY, null, 0, width);
completeImg.setRGB(startX, startY, endX- startX, endY - startY, RGB, 0, width);
}
public synchronized void finish(File f){
try {
ImageIO.write(completeImg,"bmp",f);
} catch (IOException e) {
e.printStackTrace();
}
// if (Application._devDbg) System.out.println("** ImageMerger : tous les fragments recus, ecriture du fichier final");
}
public static void main(String[] args){
Merger2 m = new Merger2(1800,1600);
m.addFragment(new File("C:\\a1.bmp"), 0, 0, 252, 600); // image, noir
m.addFragment(new File("C:\\a2.bmp"),252, 0, 800, 600); // noir , image
m.finish(new File("C:/lol.jpg"));
}
} |