概述
如何将PictureDrawable对象转换为Bitmap对象?我尝试了下面显示的以下代码,它给出了空指针.
//Convert PictureDrawable to Bitmap
private Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable){
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),pictureDrawable.getIntrinsicHeight(),Config.ARGB_8888);
Toast.makeText(HTMLActivity.this,"bitmap " + bitmap.toString(),Toast.LENGTH_LONG).show();
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());
return bitmap;
}
这是一个示例,用于显示我在代码中所做的事情;
private Picture picture;
private String url;
private WebView webview;
private Bitmap HTMLBitmap;
private PictureDrawable HTMLPicDraw;
// goal is to convert WebView --> Picture --> PictureDrawable --> Bitmap
picture = webview.capturePicture();
HTMLPicDraw = new PictureDrawable(picture);
// HTMLPicDraw a PictureDrawable object is good,no null pointer exception here
// what is left is to go from PictureDrawable to Bitmap
最后
以上就是虚心火车为你收集整理的android将drawable转成bitmap,android – 如何将PictureDrawable转换为Bitmap的全部内容,希望文章能够帮你解决android将drawable转成bitmap,android – 如何将PictureDrawable转换为Bitmap所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复