![](/img/trans.png)
[英]ImageView.getDrawingCache() null on Android 4.4.4 and below
[英]Android - ImageView.getDrawingCache() is returning null
我需要從ImageView獲取位圖,但是當我調用imageView.getDrawingCache()時,我得到了NullPointerException。 我的代碼如下:
private void getBitmapFromImageView(Bitmap bitmap)
{
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bitmap);
imageView.setRotation(90); //do something to the imageView
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
bitmap.recycle();
bitmap = Bitmap.createBitmap(imageView.getDrawingCache());
imageView.setDrawingCacheEnabled(false);
return bitmap;
}
我認為,如果要對位圖進行某些轉換,則以下方法可能更方便。
Matrix matrix = new Matrix();
// Apply your transformations here
matrix.postRotate(90);
Bitmap transformed = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.