4

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" />
NikkyD
  • 2,209
  • 1
  • 16
  • 31

2 Answers2

0

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

HHK
  • 4,852
  • 1
  • 23
  • 40
  • 1
    after knowing the issue i found this solution to be the best for my case http://stackoverflow.com/a/14054331/1092271 – NikkyD Jun 30 '14 at 12:39
-1

Use these dependency ... here 26.0.2 is a bug and Version 14 is not supportable. give these dependency:-

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.1'

    compile 'com.android.support:support-v4:27.1.1'

and Make SDK version:-

**

android {
    compileSdkVersion 27  
    defaultConfig {
        applicationId "com.example.yeshveer.mygraphics"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"}

**

But you can try once with dependency without change SDK version.

and Remember canvas.restore(); dont use

Pradeep Sheoran
  • 493
  • 6
  • 15