ImageView.getDrawable为空?
设置完iv.setImageResource(R.drawable.l)后,也要用getResources().getDrawable(R.drawable.l),而不是iv.getDrawable()。
你调用了getDrawable(R.drawable.l)两次,将会获得俩个不同的对象,因为这样会获取俩个新的ImageDrawable().
定义一个含有drawable的数组,如何通过算法得到下一个ID、上一个ID?
采取取模运算。
下一张图片ID:imageIndex = (imageIndex + 1)%images.length;
上一张图片ID:imageIndex = (imageIndex - 1 + images.length)%images.length;
如何从imageview里面得到一个bitmap对象?
imageview.getDrawable.getBitMap
如何创建剪切的bitmap位图?
public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
从原始位图剪切图像,这是一种高级的方式。可以用Matrix(矩阵)来实现旋转等高级方式截图
参数说明:
Bitmap source:要从中截图的原始位图
int x:起始x坐标
int y:起始y坐标
int width:要截的图的宽度
int height:要截的图的宽度
Bitmap.Config config:一个枚举类型的配置,可以定义截到的新位图的质量
代码:
double scale = bitmap.getWidth() / 240;
int x = (int) (event.getX() * scale);
int y = (int) (event.getY() * scale);
if(x + 120 > bitmap.getWidth()){
x = bitmap.getWidth() - 120;
}else if(y + 120 > bitmap.getHeight()){
y = bitmap.getHeight() - 120;
}