Following code shows how to concatenate the image chunks above into one image.
int rows = 2; //we assume the no. of rows and cols are known and each chunk has equal width and height int cols = 2; int chunks = rows * cols; int chunkWidth, chunkHeight; int type; //fetching image files File[] imgFiles = new File[chunks]; for (int i = 0; i < chunks; i++) { imgFiles[i] = new File("archi" + i + ".jpg"); } //creating a bufferd image array from image files BufferedImage[] buffImages = new BufferedImage[chunks]; for (int i = 0; i < chunks; i++) { buffImages[i] = ImageIO.read(imgFiles[i]); } type = buffImages[0].getType(); chunkWidth = buffImages[0].getWidth(); chunkHeight = buffImages[0].getHeight(); //Initializing the final image BufferedImage finalImg = new BufferedImage(chunkWidth*cols, chunkHeight*rows, type); int num = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { finalImg.createGraphics().drawImage(buffImages[num], chunkWidth * j, chunkHeight * i, null); num++; } } System.out.println("Image concatenated....."); ImageIO.write(finalImg, "jpeg", new File("finalImg.jpg"));
41 comments:
This was very helpful. Thank you!
hey...thankx a lot...ws helpful 4 our prjct...
Thankx Kalani, this was very helpful for may final project, since I was to start my project using java.
welcome...you all.
On line 23: shouldn't it be "chunkWidth*cols" instead of "chunkWidth*chunks" (respectively "rows")? Or not?
Anyway thanks a lot!
Thanks Knick for pointing that out. (I couldn't test this code but I'll change that)
Hi,
I gonna use your piece of code but I'm not sure about memory consumption because I would like to use it to merge a large amount of image... about 4000 images with a maximum size of 256x256x8bit / image. I'm not sure that Java will be able to handle that. Do you have any advice concerning my case ?
Thanks
hi...i need the java code for replacing some parts in image...i tried many times.but i cannot get any code for image parts replacing,i completed half of the project,if i got the java code for image parts replacing,i completed my project...plzzz plzzz help me
hi...i need the java code for replacing some parts in image...i tried many times.but i cannot get any code for image parts replacing,i completed half of the project,if i got the java code for image parts replacing,i completed my project...plzzz plzzz help me
Hello
your post is really helpful. i tried both the splitting and merging. it has a problem of rounding. for example i split my image 574 * 574 in to 4 * 4 chunks which results in 143 * 143 sized 16 chunks and when i merge all the chunks the resultant size will be the 572 * 572 , because it does not take care of rounding mistake happens with division operation. if we make more chunks say 200 then the rounding loss 100 pixels and so on.
thank u very much.........
I am getting a black image after concating the images. Any idea?
Works like a charm.
sir,
Could you please tell me if we can import this into an android project ?
And if Yes How should we go about it.
gud afternoon madam .madam i excute that code not run in netbeens .
view plainprint?
int rows = 2; //we assume the no. of rows and cols are known and each chunk has equal width and height
int cols = 2;
int chunks = rows * cols;
int chunkWidth, chunkHeight;
int type;
//fetching image files
File[] imgFiles = new File[chunks];
for (int i = 0; i < chunks; i++) {
imgFiles[i] = new File("archi" + i + ".jpg");
}
//creating a bufferd image array from image files
BufferedImage[] buffImages = new BufferedImage[chunks];
for (int i = 0; i < chunks; i++) {
buffImages[i] = ImageIO.read(imgFiles[i]);
}
type = buffImages[0].getType();
chunkWidth = buffImages[0].getWidth();
chunkHeight = buffImages[0].getHeight();
//Initializing the final image
BufferedImage finalImg = new BufferedImage(chunkWidth*cols, chunkHeight*rows, type);
int num = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
finalImg.createGraphics().drawImage(buffImages[num], chunkWidth * j, chunkHeight * i, null);
num++;
}
}
System.out.println("Image concatenated.....");
ImageIO.write(finalImg, "jpeg", new File("finalImg.jpg"));
above code is not excute please slove that code
Hi Kalani,
I am Sunil From Mumbai. I want take multiple images from DB and make one image and fetch that one image from server side to client and again extract that one image get multiple, so can we get this. Can you help me. my email id is sunilkale24@gmail.com
This is very helpful for the works. Thank u as a srilankan
Good morning mam.do you hav the code to crop a img
This code shows the error
Cant find symbol ImageIO.read();
and ImageIO.write();
i have to merge images of 30 MP resulting image will be 2*2 i.e 120 MP so i am getting out of memory error
what can i do can anyone help me
Hi Kalyani
What If I have a fifth image which is png and want to overlay above this collage. So that transparent area remains transparent in png image. Please help
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.
Prologics, India offers HDR image blending, real estate photo editing and image editing services, image clipping, background removal, photo clipping path service, photo editing, color correction, photo retouching & restoration, clipping path, cropping, resizing services, 3d floor design, 2d floor plan services & many more.
A new tool constructed for merging PDF documents doesn’t lag behind. You may combine pdfs online without extra efforts. In the best traditions of our platform, the procedure is self-explanatory and easy in usage. Our user-friendly interface attracts your attention to main moments and step-by-step leads you to the successful result.merge, altomerge, merging PDF documents, combine pdfs online
If you need any information just click here pdf merge
Best selenium online training institute `
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information,
I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
Java training in Btm layout
Java training in Jaya nagar
Java training in Electronic city
Java training in Chennai
Java training in USA
I like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting!!
aws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
I am really happy with your blog because your article is very unique and powerful for new reader.
aws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
Thank you for sharing information. Wonderful blog & good post.
aws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
Quality of an image in a document printed out should always be higher than the quality of one being viewed on the internet as when a image is printed out it needs higher quality than an image that you view on your computer. onlineconvertfree.com
lms higher education
virtual learning platforms
school management app
wow your arctile was very informative and it has solved my many quiries
Please more information on different topic please visit these links given bellow...
Top 10 CBSE Schools in Meerut
Astro Finding
Best Website Designer in Meerut
Dietitian in Meerut
Asking questions are really pleasant thing if you are not understanding anything entirely, but this article offers nice understanding yet.
Mac Crack Software
content marketing in usa
social media advertising in usa
digital solution company in usa
erp software development in usa
maintenance automation in usa
buy juicy fruit online
buy gelato strain online
Buy dark star strain online
buy hawaiian skunk strain online
buy bc big bud strain leafly
buy auto flowering seeds online
buy brass knuckles vape recall 2018
buy alaskan thunder fuck online
buy cannabis seeds bank online
Thanks for updating us with useful information
Techviky.com
Thanks for updating us with useful information
Techviky.com
Post a Comment