我是靠谱客的博主 虚心火车,最近开发中收集的这篇文章主要介绍android将drawable转成bitmap,android – 如何将PictureDrawable转换为Bitmap,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

如何将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所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部