【问题标题】:How to transfer images from wcf ksoap2 to android如何将图像从 wcf ksoap2 传输到 android
【发布时间】:2014-01-13 10:35:34
【问题描述】:

我正在尝试将图像从 wcf ksoap2 发送到 android。 在 wcf 方面,我已将所有图像转换为字节数组并将它们存储在 ArrayList 中。 在 android 端,我从 wcf 响应中填充 ArrayList。 现在的问题是字节数​​组没有正确接收,字节数组没有转换成Image/BufferedImage。

这是我的代码

        byt = new byte[4096];
        byt = (byte[]) al.get(5);
        //Image im;
        BufferedImage bImageFromConvert = null;
        InputStream in = new ByteArrayInputStream(byt);

        try {
            bImageFromConvert = ImageIO.read(in);
            //ImageIO.write(bImageFromConvert, "jpg", new File(
            //      "c:/new-darksouls.jpg"));               

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}

al 是我的 ArrayList。

【问题讨论】:

  • 你在android代码端或.net端有问题吗?
  • 我在 android 端有问题。

标签: c# java android wcf arraylist


【解决方案1】:
private String prepareImage() {
        if (tempPath == null ) {
            return "";
        }

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = BitmapFactory.decodeFile(tempPath, options);
        bitmap = Bitmap.createScaledBitmap(bitmap, 50, 50, true);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //bitmap.compress(Bitmap.CompressFormat.PNG, 50, baos);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);

        byte[] byteArray = baos.toByteArray();

        String imageString = com.size4u.utils.Base64
                .encodeBytes(byteArray);
        bitmap = null;
        System.gc();
        Runtime.getRuntime().gc();
        return imageString;
    }

【讨论】:

  • 我听不懂。我想将 byte[] 转换为 Image/BufferedImage
  • tempPath 是你的图片路径
  • 此函数返回存储字节的图像字符串,并将此字符串传递给webservice。
  • 我猜你不明白。我想将图像从 wcf 传输到 android.. 而不是从 android。我已将图像转换为 wcf 端的字节数组,现在我想在 android 接收该字节数组。
  • 请检查这个... Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);返回解码后的位图,如果图像无法解码,则返回 null。
猜你喜欢
  • 2013-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-13
  • 2017-08-04
  • 2013-05-23
  • 1970-01-01
相关资源
最近更新 更多