androidgraphicsandroid-canvascyanogenmod

android.graphics.Picture not being drawn in API 14+


When i change the targetAPI in the manifest from 13 to 14 (or higher) the Picture no longer work. No matter what or how.

Example

    Paint bluepaint = new Paint();
    bluepaint.setColor(Color.BLUE);

    Picture pic = new Picture();
        Canvas testcanvas = pic.beginRecording(300, 300);
        testcanvas.drawColor(Color.BLUE);
    pic.endRecording();

    canvas.drawColor(Color.RED);
    canvas.drawLine(0, 0, 480, 480, bluepaint);

    canvas.drawPicture(pic);

This should draw a blue screen from the pic, it does so in API 13 and lower. It does NOT draw the blue but only the red from the pure canvas.draw call.

I can't see any change from API 13 to 14 that would explain this.

However i am using cyanogenmod on a Galaxy S2 (so i can run 4.3), not sure if they change native stuff on cyanogen, switched to it couple of weeks ago.

Any idea where to look for answers or what could cause this ?

edit

working

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="13" />

NOT working

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="14" />

Solution

  • If targetSdkVersion is 14 (Ice Cream Sandwich) or higher then hardware acceleration is enabled by default for the whole app. Unfortunately Canvas.drawPicture() is not supported if hardware acceleration is enabled.

    There are two way to fix this:

    1. Add android:hardwareAccelerated="false" to the application tag in your AndroidManifest.xml. This will disable hardware acceleration for your whole app.

    2. You can use Bitmap and Canvas.drawBitmap() which is supported with hardware acceleration.

    Reference: http://developer.android.com/guide/topics/graphics/hardware-accel.html