Android的:如何以原始大小显示图像 [英] Android: How to display an image in its original size

查看:137
本文介绍了Android的:如何以原始大小显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建字节数组中的位图图像,并在一个ImageView的显示。该的android:layout_width 安卓layout_height ImageView的都设置为WRAP_CONTENT,而机器人:scaleType 设置为中心。但图像依然缩放到屏幕的大小。

有没有办法在原来的大小显示图像(就像使用了android:直接src属性)?

code:

从字节数组创建位图:

 私人位图德$ C $的CBitmap(byte []的数据){
    返回BitmapFactory.de codeByteArray(数据,0,data.length);
}
 

和ImageView的布局:

 < ImageView的
    机器人:ID =@ + ID /标志
    机器人:scaleType =centerInside
    机器人:adjustViewBounds =真
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT/>
 

设置图像的ImageView:

  mView.setImageBitmap(mBitmap);
 

解决方案

请使用code 如果流是从资源

 的InputStream是= this.getResources()openRawResource(imageId1)。
位图originalBitmap = BitmapFactory.de codeStream(是);
ImageView的myimage.setImageBitmap(originalBitmap);
myimage.setScaleType(ScaleType.MATRIX);
 

I create an bitmap image from byte array and display it in an ImageView. The android:layout_width and android:layout_height of the ImageView are set to wrap_content, and the android:scaleType is set to center. But the image is still scaled to the screen size.

Is there a way to display the image at its original size (just like using the android:src attribute directly)?

CODE:

create bitmap from byte array:

private Bitmap decodeBitmap(byte[] data) {
    return BitmapFactory.decodeByteArray(data, 0, data.length);
}

and layout of the ImageView:

<ImageView
    android:id="@+id/logo"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />     

set image to ImageView:

mView.setImageBitmap(mBitmap);

解决方案

Please use this code if the stream is from resource

InputStream is = this.getResources().openRawResource(imageId1); 
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
ImageView myimage.setImageBitmap(originalBitmap); 
myimage.setScaleType(ScaleType.MATRIX); 

这篇关于Android的:如何以原始大小显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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