android - 如何剪切图像的某些部分并在imageview中显示 [英] android - How to cut some part of image and show it in imageview

查看:18
本文介绍了android - 如何剪切图像的某些部分并在imageview中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在 imageview 中显示图像的一部分.见下图.

I want to show only some part of image in imageview. See following image .

在 google+ 应用中可以找到相同的示例,您可以在其中看到所有带有图片的帖子.

Same example can be found in google+ app where you see all posts with images.

任何链接,代码都会有所帮助.谢谢

Any links ,code will be helpful. Thanks

推荐答案

使用这段代码

int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidth = 200;
int newHeight = 200;

// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;

// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);

// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
                  width, height, matrix, true); 

// make a Drawable from Bitmap to allow to set the BitMap 
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

ImageView imageView = new ImageView(this);

// set the Drawable on the ImageView
imageView.setImageDrawable(bmd);

这篇关于android - 如何剪切图像的某些部分并在imageview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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