本文介绍了Android-显示大图的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否仍然要显示大图像的一部分-图像为16000 * 320当我在Android Studio中使用ImageView尝试此操作时,通常可以在activity_main.xml设计下获得其外观,直到我生成.apk,然后图像消失并在Tablet上运行时,它也是空白.

Is there Anyway to Display part of a large image - the image is 16000*320When Ive tried this in Android Studio using ImageView I can usually get what looks like its going to work under activity_main.xml Design, until I build .apk then the image disapears and running it on my Tablet it is also blank.

推荐答案

在布局xml文件中添加ImageView:

Add an ImageView in your layout xml file:

<ImageView
    android:id="@+id/myImage"
    android:layout_width="100dp"
    android:layout_height="100dp"/>

在您的活动中:

ImageView mImageView = (ImageView) findViewById(R.id.myImage);

然后使用 BitmapRegionDecoder :

// Get image width and height:
InputStream inputStream = getAssets().open("large_image.jpg");
BitmapFactory.Options tmpOptions = new BitmapFactory.Options();
tmpOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, tmpOptions);
int width = tmpOptions.outWidth;
int height = tmpOptions.outHeight;

// Crop image:
// Crop a rect with 200 pixel width and height from center of image
BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(width / 2 - 100, height / 2 - 100, width / 2 + 100, height / 2 + 100), options);
mImageView.setImageBitmap(bitmap);

来自此处的代码

这篇关于Android-显示大图的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:15