小编Jam*_*sEX的帖子

尝试绘制用户加载的位图

我正在尝试绘制用户加载的位图.这是在onCreate.

imageView = (ImageView) this.findViewById(R.id.ImageView);

Display currentDisplay = getWindowManager().getDefaultDisplay();
float dw = currentDisplay.getWidth();
float dh = currentDisplay.getHeight();
bitmap = Bitmap.createBitmap((int) dw, (int) dh,
        Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(Color.BLUE);
imageView.setImageBitmap(bitmap);
imageView.setOnTouchListener(this);
Run Code Online (Sandbox Code Playgroud)

下一个代码是当用户按下按钮以获取位图并且在成功检索位图之后.它在" onActivityResult" 结尾

canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(Color.BLUE);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
imageView.setOnTouchListener(this);
Run Code Online (Sandbox Code Playgroud)

我能够绘制在期间制作的空白位图onCreate,但是当用户加载新位图并尝试绘制它时不会显示.但是加载了新的位图.

我也厌倦了

canvas = new Canvas(BitmapFactory.decodeFile(picturePath));
Run Code Online (Sandbox Code Playgroud)

然后它给了我错误.

谁知道我做错了什么?

编辑:这是日志文件:

10-25 03:19:31.409: W/System.err(1971): java.lang.Exception: java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
10-25 03:19:31.409: W/System.err(1971):     at com.example.milestone2.Draw.onActivityResult(Draw.java:148)
10-25 …
Run Code Online (Sandbox Code Playgroud)

android bitmap draw imageview android-canvas

8
推荐指数
1
解决办法
8862
查看次数

标签 统计

android ×1

android-canvas ×1

bitmap ×1

draw ×1

imageview ×1