Tag: 位图

如何将Drawable转换为位图?

我想设置一个特定的Drawable作为设备的壁纸,但所有壁纸function只接受Bitmap s。 我无法使用WallpaperManager因为我在2.1之前。 此外,我的绘图从网上下载,不居住在R.drawable 。

BitmapFactory返回null位图

我试图从StaticConfig.getMyUser().getAvatar()的URL中获取位图。 url如下: “android/photo.jpg” 。 当我使用下面的代码时, src为空。 我不知道为什么。 我目前正在研究这个链接,但我仍然无能为力。 private void setImageAvatar(Context context){ Resources res = getResources(); Bitmap src; byte[] decodedString = Base64.decode(StaticConfig.getMyUser().getAvatar(), Base64.DEFAULT); src = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); if(src == null){ Log.e(“UserProf”,”src is null”); } // code to do something with src here }

将Java位图转换为字节数组

Bitmap bmp = intent.getExtras().get(“data”); int size = bmp.getRowBytes() * bmp.getHeight(); ByteBuffer b = ByteBuffer.allocate(size); bmp.copyPixelsToBuffer(b); byte[] bytes = new byte[size]; try { b.get(bytes, 0, bytes.length); } catch (BufferUnderflowException e) { // always happens } // do something with byte[] 在调用copyPixelsToBuffer之后,当我查看缓冲区时,字节全部为0 …从相机返回的位图是不可变的,但这不应该因为它正在进行复制。 这段代码有什么问题?