如何在服务器上显示或使用从 Android 手机接收的图像
我正在从 Android 手机发送图像到处理它的服务器,但现在我对如何在服务器中使用图像感到困惑我
发送图像的 Android 手机代码是
Log.i("sAMPLE","Info:" );
//String postURL = HOST_SERVER_URL + HOST_PHOTO_UPLOAD_URI;
String postURL ="http://10.0.2.2:8080/SimpleServlet/simple-servlet";//server URL
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(postURL);
ByteArrayBody bab = new ByteArrayBody(imageBytes, "file_name_ignored");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("source", bab);
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
,处理服务器中图像的代码是像这样
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
System.out.println("Before Mutlipart");
if(!isMultipart)
throw new ServletException("upload using multipart");
ServletFileUpload upload = new ServletFileUpload(fif);
upload.setSizeMax(1024 * 1024 * 10 /* 10 mb */);
List<FileItem> items;
try {
items = upload.parseRequest(req);
//}// catch (FileUploadException e) {
// throw new ServletException(e);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
throw new ServletException(e);
}
if(items == null || items.size() == 0)
throw new ServletException("No items uploaded");
FileItem item = items.get(0);
//BufferedImage Img=item.getString();
System.out.println(item.getContentType());
byte[]data=item.get();
现在我如何使用字节数组在服务器上显示图像或使用其他一些东西(如字符串、其他图像等)编辑图像。
I am sending an image from android phone to the server which hanldes it ,but now i am confused on how to use the image in the server
my code for android phone which sends the image is
Log.i("sAMPLE","Info:" );
//String postURL = HOST_SERVER_URL + HOST_PHOTO_UPLOAD_URI;
String postURL ="http://10.0.2.2:8080/SimpleServlet/simple-servlet";//server URL
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(postURL);
ByteArrayBody bab = new ByteArrayBody(imageBytes, "file_name_ignored");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("source", bab);
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
and my code which handles the image in the server is like this
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
System.out.println("Before Mutlipart");
if(!isMultipart)
throw new ServletException("upload using multipart");
ServletFileUpload upload = new ServletFileUpload(fif);
upload.setSizeMax(1024 * 1024 * 10 /* 10 mb */);
List<FileItem> items;
try {
items = upload.parseRequest(req);
//}// catch (FileUploadException e) {
// throw new ServletException(e);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
throw new ServletException(e);
}
if(items == null || items.size() == 0)
throw new ServletException("No items uploaded");
FileItem item = items.get(0);
//BufferedImage Img=item.getString();
System.out.println(item.getContentType());
byte[]data=item.get();
now how do i use the byte array to display the image on the server or use to edit the image with some other stuffs like string,other image etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这应该适合你...
http://www.mkyong.com/java/how-to-convert-byte-to-bufferedimage-in-java/
在服务器端(imageInByte 是你的数据[])...
I think this should work for you...
http://www.mkyong.com/java/how-to-convert-byte-to-bufferedimage-in-java/
on the server side (imageInByte is your data[])...