Compartilhar via


View.GetDrawingCache(Boolean) Method

Definition

Returns the bitmap in which this view drawing is cached.

[Android.Runtime.Register("getDrawingCache", "(Z)Landroid/graphics/Bitmap;", "GetGetDrawingCache_ZHandler")]
public virtual Android.Graphics.Bitmap? GetDrawingCache (bool autoScale);
[<Android.Runtime.Register("getDrawingCache", "(Z)Landroid/graphics/Bitmap;", "GetGetDrawingCache_ZHandler")>]
abstract member GetDrawingCache : bool -> Android.Graphics.Bitmap
override this.GetDrawingCache : bool -> Android.Graphics.Bitmap

Parameters

autoScale
Boolean

Indicates whether the generated bitmap should be scaled based on the current density of the screen when the application is in compatibility mode.

Returns

A bitmap representing this view or null if cache is disabled.

Attributes

Remarks

Returns the bitmap in which this view drawing is cached. The returned bitmap is null when caching is disabled. If caching is enabled and the cache is not ready, this method will create it. Calling #draw(android.graphics.Canvas) will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling this method and draw it on screen if the returned bitmap is not null.

Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view. Because this bitmap will be drawn scaled by the parent ViewGroup, the result on screen might show scaling artifacts. To avoid such artifacts, you should call this method by setting the auto scaling to true. Doing so, however, will generate a bitmap of a different size than the view. This implies that your application must be able to handle this size.

This member is deprecated. The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, #setLayerType(int, Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call #draw(Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.

Java documentation for android.view.View.getDrawingCache(boolean).

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

See also