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

穿精又带淫゛_ 提交于 2019-11-28 05:27:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!