如何裁剪图像中的android? [英] How to crop an image in android?

查看:123
本文介绍了如何裁剪图像中的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  如何裁剪在Android上的解析图像?

我有一个形象在我RES /绘制文件夹,我想裁剪加载到一个ImageView的时候(即切出图像的某些部分)的图像。但是我不能确定如何做到这一点,有什么建​​议?

I have an image in my res/drawable folder and I would like to crop (i.e. slice out some part of the image) the image when loading it into an ImageView. However I am unsure how to do this, any suggestions?

推荐答案

从<一个href="http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap">Bitmap.createBitmap: 返回从源位图的指定子集的不可变位图。新的位图可以是相同的对象作为源,或副本可能已被制成,它与相同密度为原始位图初始化。

From Bitmap.createBitmap: "Returns an immutable bitmap from the specified subset of the source bitmap. The new bitmap may be the same object as source, or a copy may have been made. It is initialized with the same density as the original bitmap."

传递给它一个位图,以及将其新的位图将要创建的矩形。

Pass it a bitmap, and define the rectangle from which the new bitmap will be created.

// Take 10 pixels off the bottom of a Bitmap
Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, 0, 0, originalBmp.getWidth(), originalBmp.getHeight()-10);

这篇关于如何裁剪图像中的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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