Android Canvas.drawPicture not working on devices with ice cream sandwich

I want to draw a Picture on Canvas on

 mCanvas.drawpicture(mPicture, mRect) 

Using the target API 7 <uses-sdk android:minSdkVersion="7"/> , it works fine on devices with API <14, but it does not work on devices with Ice Cream Sandwich. Apparently this is because canvas.drawPicture is not supported by hardware acceleration: Unsupported drawing operations I tried to fix this by disabling hardware acceleration in the manifest:

 <application android:hardwareAccelerated="false" ...> 

but still not working.

+3
android canvas hardware-acceleration
Apr 30 '12 at 13:37
source share
2 answers

I had the same problem and was solved by software disabling hardware acceleration only in the view that will draw Picture

 view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

However, setLayerType is only supported with API 11. Therefore, use this method:

 public static void setHardwareAccelerated(View view, boolean enabled){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){ if(enabled) view.setLayerType(View.LAYER_TYPE_HARDWARE, null); else view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } } 
+6
Dec 27 '12 at 11:58
source share

Try replacing drawPicture with drawBitmap . The syntax is pretty much the same, you just need to pass in the original rectangle (just make it the size of the image) and paint (which, if you don't edit the image, can be zero).

+5
Apr 30 2018-12-12T00:
source share



All Articles