问题
I want to draw a Picture
on a Canvas
by
mCanvas.drawpicture(mPicture, mRect)
Using target API 7 <uses-sdk android:minSdkVersion="7"/>
, it works perfectly in devices with API<14, but in devices with Ice Cream Sandwich, it doesn't work. Apparently this is because canvas.drawPicture is not supported with Hardware Acceleration: Unsupported Drawing Operations
I have tried to fix this by disabling the Hardware Acceleration in the Manifest:
<application android:hardwareAccelerated="false" ...>
but still does't work.
回答1:
I had the same problem and solved by programmatically turning off hardware acceleration only on the view that will draw the Picture
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
However setLayerType is only supported since API 11. So use this method instead:
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);
}
}
回答2:
Try replacing drawPicture
with drawBitmap
. The syntax is almost the same, you just need to pass a source rectangle (just make it the size of the image) and a paint (which if you're not editing the image can be null).
来源:https://stackoverflow.com/questions/10384613/android-canvas-drawpicture-not-working-in-devices-with-ice-cream-sandwich