如何以显示图像的一部分? [英] How to display a part of an image?
本文介绍了如何以显示图像的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大的图像。但我必须要显示它只是一些部分。如何采用Android ImageView的是这可能吗?
I have a large image. But i have to display just some portion of it. How is this possible using Android ImageView?
推荐答案
您总是可以裁剪如果您通过 Bitmap.createBitmap()
静态方法所需要的片,和然后将其分配给视图:
You could always crop the piece that you need via the Bitmap.createBitmap()
static method, and then assign it to the view:
喜欢的东西...
// Set some constants
private static final Bitmap SOURCE_BITMAP = BitmapFactory.decodeFile(....); // Get the source Bitmap using your favorite method :-)
private static final int START_X = 10;
private static final int START_Y = 15;
private static final int WIDTH_PX = 100;
private static final int HEIGHT_PX = 100;
// Crop bitmap
Bitmap newBitmap = Bitmap.createBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, false);
// Assign new bitmap to ImageView
ImageView image = (ImageView)findViewById(R.id.image_view);
image.setImageBitmap(newBitmap);
这篇关于如何以显示图像的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文