• Post Reply Bookmark Topic Watch Topic
  • New Topic

Uploading multiple image files  RSS feed

 
Kanneeswaran Kotteswaran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...All,
I have a doubt in servlet..
Can Anyone there to solve My prob?

1.Client is uploading Multiple image files at a time..

2.He is getting a final image file which is a Merged Image file of all the uploaded image files..

3.Client has to download his Final image file in to his local machine..And if he double clicks on it,the final image has to open..

This is what the actual scenario..

I hv done it on my local Machine..
I dont know know how to do it using servlets..

Here I am pasting my code..
Can anyone do it using servlets???
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class POCTest {
public static void main(String ar[]) {
int rows = 2;
int cols = 2;
int chunks = rows * cols;

int chunkWidth, chunkHeight;
int type;
//fetching image files
File[] imgFiles = new File[chunks];
for (int j = 0; j < chunks; j++) {
imgFiles[j] = new File("C:/archi" + j + ".jpg");
}

//creating a bufferd image array from image files
BufferedImage[] buffImages = new BufferedImage[chunks];
try {
for (int k = 0; k < chunks; k++) {
buffImages[k] = ImageIO.read(imgFiles[k]);
}
}catch(Exception ex) {
ex.printStackTrace();
}
type = buffImages[0].getType();
chunkWidth = buffImages[0].getWidth();
chunkHeight = buffImages[0].getHeight();

//Initializing the final image
BufferedImage finalImg = new BufferedImage(chunkWidth*chunks, chunkHeight*chunks, 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.....");
try {
ImageIO.write(finalImg, "jpeg", new File("C:/finalImg.jpg"));
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
 
manoj r patil
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you write only specific problem? E.g. if you have working code for image processing, don't paste it in your post.
 
Kanneeswaran Kotteswaran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


1.Is that possible to send many requests(Images in our view) at a time?

2.we are merging that files on the server..
And the Final Image should be in Downloadable format...
How to do it?


 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look a this FAQ entry.
http://faq.javaranch.com/java/FileUpload
It lists a few of the more popular libraries for uploading files.

I use Fileupload from Apache.
Yes, it can support multiple files in a single upload.
There is sample code on their site.

BTW: In a forum named 'Servlets" the title "SERVLETS" is just about as undescriptive as possible.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

Also, please UseAMeaningfulSubjectLine when posting. Explaining your question or remark briefly on the subject line allows us to know what we are getting into, and if we will be able to help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!