我有一张地图图片,想要使用Picasso
库加载地图。加载地图后,我想在其上绘制canvas
但我收到此错误。
java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
at android.graphics.Canvas.<init>(Canvas.java:127)
at com.example.sev_user.smarthome.gui.fragment.MapFragment$1.onBitmapLoaded(MapFragment.java:108)
at com.squareup.picasso.TargetAction.complete(TargetAction.java:36)
at com.squareup.picasso.Picasso.deliverAction(Picasso.java:557)
at com.squareup.picasso.Picasso.complete(Picasso.java:509)
at com.squareup.picasso.Picasso$1.handleMessage(Picasso.java:116)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4950)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
at dalvik.system.NativeStart.main(Native Method)
这是我的代码:
final Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
mMapCanvas = new Canvas(bitmap);
mIvMap.setImageBitmap(bitmap);
reloadMap();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
mIvMap.setTag(target);
Picasso.with(getActivity())
.load(R.drawable.housemap)
.config(Bitmap.Config.RGB_565)
.into(target);
据我所知,canvas需要一个可变的位图,但我不想使用bitmap.copy()
。
它可能与这篇文章有关:Draw a line on ImageView set by Picasso但我需要一些东西不能创建新的位图。
请帮助我!