如何显示或使用来自Android手机收到的服务器上的图像 [英] how to display or use an image received from Android phone on the server

查看:205
本文介绍了如何显示或使用来自Android手机收到的服务器上的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从Android手机发送图像到hanldes它的服务器上,但现在我很困惑如何在服务器中使用的图像

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

我的code的android手机,它发送图像

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); 

和我的code负责处理在服务器中的形象是这样的。

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.

推荐答案

我想这应该工作,你...

I think this should work for you...

HTTP://www.mkyong .COM / JAVA /如何到转换字节到BufferedImage的 - 在的Java /

在服务器端(imageInByte是你的数据[])...

on the server side (imageInByte is your data[])...

//convert byte array back to BufferedImage
InputStream in = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = ImageIO.read(in);

ImageIO.write(bImageFromConvert, "jpg", 
         new File("c:\\image\\mypic_new.jpg")); 

这篇关于如何显示或使用来自Android手机收到的服务器上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆