Dela via


Canvas.SaveLayer Method

Definition

Overloads

SaveLayer(Single, Single, Single, Single, Paint, SaveFlags)

Helper version of saveLayer() that takes 4 values rather than a RectF.

SaveLayer(Single, Single, Single, Single, Paint)

Convenience for #saveLayer(RectF, Paint) that takes the four float coordinates of the bounds rectangle.

SaveLayer(RectF, Paint, SaveFlags)

This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen bitmap.

SaveLayer(RectF, Paint)

This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target.

SaveLayer(Single, Single, Single, Single, Paint, SaveFlags)

Helper version of saveLayer() that takes 4 values rather than a RectF.

[Android.Runtime.Register("saveLayer", "(FFFFLandroid/graphics/Paint;I)I", "GetSaveLayer_FFFFLandroid_graphics_Paint_IHandler")]
public virtual int SaveLayer (float left, float top, float right, float bottom, Android.Graphics.Paint? paint, Android.Graphics.SaveFlags saveFlags);
[<Android.Runtime.Register("saveLayer", "(FFFFLandroid/graphics/Paint;I)I", "GetSaveLayer_FFFFLandroid_graphics_Paint_IHandler")>]
abstract member SaveLayer : single * single * single * single * Android.Graphics.Paint * Android.Graphics.SaveFlags -> int
override this.SaveLayer : single * single * single * single * Android.Graphics.Paint * Android.Graphics.SaveFlags -> int

Parameters

left
Single
top
Single
right
Single
bottom
Single
paint
Paint
saveFlags
SaveFlags

Returns

Attributes

Remarks

Helper version of saveLayer() that takes 4 values rather than a RectF.

As of API Level API level Build.VERSION_CODES#P the only valid saveFlags is #ALL_SAVE_FLAG. All other flags are ignored.

This member is deprecated. Use #saveLayer(float, float, float, float, Paint) instead.

Java documentation for android.graphics.Canvas.saveLayer(float, float, float, float, android.graphics.Paint, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SaveLayer(Single, Single, Single, Single, Paint)

Convenience for #saveLayer(RectF, Paint) that takes the four float coordinates of the bounds rectangle.

[Android.Runtime.Register("saveLayer", "(FFFFLandroid/graphics/Paint;)I", "GetSaveLayer_FFFFLandroid_graphics_Paint_Handler")]
public virtual int SaveLayer (float left, float top, float right, float bottom, Android.Graphics.Paint? paint);
[<Android.Runtime.Register("saveLayer", "(FFFFLandroid/graphics/Paint;)I", "GetSaveLayer_FFFFLandroid_graphics_Paint_Handler")>]
abstract member SaveLayer : single * single * single * single * Android.Graphics.Paint -> int
override this.SaveLayer : single * single * single * single * Android.Graphics.Paint -> int

Parameters

left
Single
top
Single
right
Single
bottom
Single
paint
Paint

Returns

Attributes

Remarks

Convenience for #saveLayer(RectF, Paint) that takes the four float coordinates of the bounds rectangle.

Java documentation for android.graphics.Canvas.saveLayer(float, float, float, float, android.graphics.Paint).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SaveLayer(RectF, Paint, SaveFlags)

This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen bitmap.

[Android.Runtime.Register("saveLayer", "(Landroid/graphics/RectF;Landroid/graphics/Paint;I)I", "GetSaveLayer_Landroid_graphics_RectF_Landroid_graphics_Paint_IHandler")]
public virtual int SaveLayer (Android.Graphics.RectF? bounds, Android.Graphics.Paint? paint, Android.Graphics.SaveFlags saveFlags);
[<Android.Runtime.Register("saveLayer", "(Landroid/graphics/RectF;Landroid/graphics/Paint;I)I", "GetSaveLayer_Landroid_graphics_RectF_Landroid_graphics_Paint_IHandler")>]
abstract member SaveLayer : Android.Graphics.RectF * Android.Graphics.Paint * Android.Graphics.SaveFlags -> int
override this.SaveLayer : Android.Graphics.RectF * Android.Graphics.Paint * Android.Graphics.SaveFlags -> int

Parameters

bounds
RectF

May be null. The maximum size the offscreen bitmap needs to be (in local coordinates)

paint
Paint

This is copied, and is applied to the offscreen when restore() is called.

saveFlags
SaveFlags

see _SAVE_FLAG constants, generally #ALL_SAVE_FLAG is recommended for performance reasons.

Returns

value to pass to restoreToCount() to balance this save()

Attributes

Remarks

This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen bitmap. <p class="note"><strong>Note:</strong> this method is very expensive, incurring more than double rendering cost for contained content. Avoid using this method, especially if the bounds provided are large. It is recommended to use a android.view.View#LAYER_TYPE_HARDWARE hardware layer on a View to apply an xfermode, color filter, or alpha, as it will perform much better than this method.

All drawing calls are directed to a newly allocated offscreen bitmap. Only when the balancing call to restore() is made, is that offscreen buffer drawn back to the current target of the Canvas (either the screen, it's target Bitmap, or the previous layer).

Attributes of the Paint - Paint#getAlpha() alpha, Paint#getXfermode() Xfermode, and Paint#getColorFilter() ColorFilter are applied when the offscreen bitmap is drawn back when restore() is called.

As of API Level API level Build.VERSION_CODES#P the only valid saveFlags is #ALL_SAVE_FLAG. All other flags are ignored.

This member is deprecated. Use #saveLayer(RectF, Paint) instead.

Java documentation for android.graphics.Canvas.saveLayer(android.graphics.RectF, android.graphics.Paint, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SaveLayer(RectF, Paint)

This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target.

[Android.Runtime.Register("saveLayer", "(Landroid/graphics/RectF;Landroid/graphics/Paint;)I", "GetSaveLayer_Landroid_graphics_RectF_Landroid_graphics_Paint_Handler")]
public virtual int SaveLayer (Android.Graphics.RectF? bounds, Android.Graphics.Paint? paint);
[<Android.Runtime.Register("saveLayer", "(Landroid/graphics/RectF;Landroid/graphics/Paint;)I", "GetSaveLayer_Landroid_graphics_RectF_Landroid_graphics_Paint_Handler")>]
abstract member SaveLayer : Android.Graphics.RectF * Android.Graphics.Paint -> int
override this.SaveLayer : Android.Graphics.RectF * Android.Graphics.Paint -> int

Parameters

bounds
RectF

May be null. The maximum size the offscreen render target needs to be (in local coordinates)

paint
Paint

This is copied, and is applied to the offscreen when restore() is called.

Returns

value to pass to restoreToCount() to balance this save()

Attributes

Remarks

This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target. <p class="note"><strong>Note:</strong> this method is very expensive, incurring more than double rendering cost for contained content. Avoid using this method when possible and instead use a android.view.View#LAYER_TYPE_HARDWARE hardware layer on a View to apply an xfermode, color filter, or alpha, as it will perform much better than this method.

All drawing calls are directed to a newly allocated offscreen rendering target. Only when the balancing call to restore() is made, is that offscreen buffer drawn back to the current target of the Canvas (which can potentially be a previous layer if these calls are nested).

Attributes of the Paint - Paint#getAlpha() alpha, Paint#getXfermode() Xfermode, and Paint#getColorFilter() ColorFilter are applied when the offscreen rendering target is drawn back when restore() is called.

Java documentation for android.graphics.Canvas.saveLayer(android.graphics.RectF, android.graphics.Paint).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to