-1
A
回答
1
希望這有助於
Bitmap bitmapIcon = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
+0
感謝您的回答。但是,我想將通知對象中的圖標轉換爲位圖。 – user212942
1
你可以使用這個類。另外我通常使用這個代碼。
public static Bitmap drawableToBitmap (Drawable drawable) {
Bitmap bitmap = null;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if(bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
+0
感謝您的回答。但Notification.getSmallIcon()返回的不是Drawable,而是Icon對象... – user212942
相關問題
- 1. android將位圖轉換爲ascii位圖
- 2. 在Android中將位圖轉換爲GrayScale
- 3. 將位圖轉換爲圖標
- 4. 將位圖轉換爲圖標
- 5. 如何將位圖轉換爲圖像
- 6. 如何將AChartEngine圖轉換爲位圖
- 7. 在Android中將視圖轉換爲位圖圖像
- 8. 如何將圖像轉換爲圖標?
- 9. 如何在Android中將PDF轉換爲位圖?
- 10. 如何在Android中將畫布轉換爲位圖?
- 11. 在Android中運行時轉換時將SVG轉換爲位圖
- 12. 將視圖轉換爲位圖而不顯示在Android中?
- 13. android將位圖轉換爲bufferedinputstream
- 14. 將位圖轉換爲byteArray android
- 15. Android:將字符串轉換爲位圖
- 16. Android Studio - 將位圖轉換爲java.io.File
- 17. 如何將byteArray轉換爲位圖圖像以在Android中的imageview中顯示?
- 18. Android:將位圖轉換爲單色位圖(每像素1位)
- 19. 如何將ImageSource轉換爲位圖?
- 20. 如何將位圖轉換爲Drawable?
- 21. 如何將位圖轉換爲幀?
- 22. 如何將位圖轉換爲Uri?
- 23. 如何將smartimageview轉換爲位圖?
- 24. 如何將bitmatrix轉換爲位圖?
- 25. 如何將PictureDrawable轉換爲位圖
- 26. 如何將位圖轉換爲int []?
- 27. 如何將位圖轉換爲intptr C#
- 28. 如何將位圖轉換爲視頻?
- 29. 如何將24位圖像轉換爲16位rgb565位圖?
- 30. 如何將位圖轉換爲Android中的鉛筆素描?
感謝所有。我用Reflection方法(loadDrawableInner)解決了這個問題。 – user212942
我不認爲這個問題是一個完整的重複,儘管類似。不同之處在於'Icon'不是'Drawable',但是你可以使用'icon.loadDrawable(context)'''Icon'獲得'Drawable'' – rintcius