如何阅读绘制位为InputStream的 [英] How to read drawable bits as InputStream

查看:140
本文介绍了如何阅读绘制位为InputStream的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有说,一些的ImageView 对象。我想读比特/这个对象为InputStream的原始数据。那怎么办?

There's say some ImageView object. I want to read bits/raw data of this object as InputStream. How to do that?

推荐答案

首先得为可绘制的对象ImageView的背景图像

First get Background image of the imageview as an object of Drawable

iv.getBackground();

然后,使用转换Drwable图像转换成位图

Then convert Drwable image into bitmap using

BitmapDrawable bitDw = ((BitmapDrawable) d);
        Bitmap bitmap = bitDw.getBitmap();

现在,应使用ByteArrayOutputStream来获取位图到流并获取字节组[] ByteArray的转换成ByteArrayInputStream的

Now use ByteArrayOutputStream to get the bitmap into the stream and get bytearray[] convert bytearray into ByteArrayInputStream

您可以使用下面的code,以获得ImageView的输入流

you can use the following code to get inputstream from imageview

ImageView iv = (ImageView) findViewById(R.id.splashImageView);
    Drawable d =iv.getBackground();
    BitmapDrawable bitDw = ((BitmapDrawable) d);
    Bitmap bitmap = bitDw.getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] imageInByte = stream.toByteArray();
    System.out.println("........length......"+imageInByte);
    ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);

谢谢 迪帕克

Thanks Deepak

这篇关于如何阅读绘制位为InputStream的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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