ImageRef

class ImageRef(uniqueId: UUID?, acquireStrongReference: Boolean) : Drawable, Parcelable, AutoCloseable

Constructors

Link copied to clipboard
constructor(uniqueId: UUID?, acquireStrongReference: Boolean)

Types

Link copied to clipboard

Properties

Link copied to clipboard

Unique id of the native resource the object points to.

Functions

Link copied to clipboard
fun clear()

Releases native resources stored by the ref. If two different ImageRef objects have the same uniqueId both of them become cleared.

Link copied to clipboard
open override fun close()

Releases strong reference to the image

Link copied to clipboard
open override fun describeContents(): Int
Link copied to clipboard
open override fun draw(canvas: Canvas)
Link copied to clipboard
external fun encodeImage(options: EncodeImageOptions = EncodeImageOptions()): Result<ByteArray>

Returns the stored image encoded with the given options.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun getAlpha(): Int
Link copied to clipboard
Link copied to clipboard
open override fun getIntrinsicHeight(): Int
Link copied to clipboard
open override fun getIntrinsicWidth(): Int
Link copied to clipboard
open override fun getOpacity(): Int
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
external fun hibernate(): Result<Unit>

Compresses ImageRef and stores it either on disk or in memory according to global settings.

Link copied to clipboard
external fun info(): Result<ImageInfo>

Information about stored image.

Link copied to clipboard

Marks the cached drawable render as stale so the next draw re-renders the source image. Call this if the underlying image bytes change.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external fun renderToBitmap(target: Bitmap): Result<Unit>

Renders the stored image into a caller-provided mutable ARGB_8888 Bitmap.

Link copied to clipboard

Renders the stored image into a caller-provided HardwareBuffer with format HardwareBuffer.RGBA_8888. Combined with Bitmap.wrapHardwareBuffer (API 29+) this enables zero-copy GPU sampling — HWUI imports the buffer as an EGL/Vulkan external image once and samples it directly on subsequent draws.

Link copied to clipboard
external fun saveImage(path: String, options: SaveImageOptions = SaveImageOptions()): Result<Unit>

Saves the stored image with the given options.

Link copied to clipboard

Converts ImageRef to serialized string representation with acquiring serialized reference to the native resource. You must eventually call deserialize, otherwise the reference will leak

Link copied to clipboard
open override fun setAlpha(alpha: Int)
Link copied to clipboard
open override fun setColorFilter(colorFilter: ColorFilter?)
Link copied to clipboard
fun setOptimizeDrawableSize(optimizeImageSize: Boolean)

If true, the drawable will render the image at the size of its bounds instead of the full image size. This can reduce memory usage and improve performance when rendering large images in small views. If for some reason you need to render the full image size, set this to false. The default is true. Possible cases when you need to render full quality image that might be zoomed later.

Link copied to clipboard
external fun toBitmap(): Result<Bitmap>

Returns stored image as a bitmap

Link copied to clipboard
fun toJson(imageSerializationMode: ImageSerializationMode): JSONObject

Converts the Image Ref to Json representation If serialization mode is REFERENCE effectively calls serialize If serialization mode is BUFFER stores the image inplace in base64 format

Link copied to clipboard
open override fun writeToParcel(parcel: Parcel, flags: Int)