pub struct Bitmap { /* private fields */ }
bitmap
only.Expand description
An immediate wrapper over android.graphics.Bitmap
Implementations§
source§impl Bitmap
impl Bitmap
sourcepub unsafe fn from_jni(env: *mut JNIEnv, bitmap: jobject) -> Self
pub unsafe fn from_jni(env: *mut JNIEnv, bitmap: jobject) -> Self
Create a Bitmap
wrapper from JNI pointers
§Safety
This function should be called with a healthy JVM pointer and with a non-null
android.graphics.Bitmap
, which must be kept alive on the Java/Kotlin side.
sourcepub fn info(&self) -> Result<BitmapInfo>
pub fn info(&self) -> Result<BitmapInfo>
Fills out and returns the BitmapInfo
struct for the given Java bitmap object.
sourcepub fn data_space(&self) -> DataSpace
Available on crate feature api-level-30
only.
pub fn data_space(&self) -> DataSpace
api-level-30
only.Returns the DataSpace
of this Bitmap
.
Note that DataSpace
only exposes a few values. This may return DataSpace::Unknown
,
even for Named ColorSpaces, if they have no corresponding DataSpace
.
sourcepub fn lock_pixels(&self) -> Result<*mut c_void>
pub fn lock_pixels(&self) -> Result<*mut c_void>
Attempt to lock the pixel address.
Locking will ensure that the memory for the pixels will not move until the
Bitmap::unlock_pixels()
call, and ensure that, if the pixels had been previously purged,
they will have been restored.
If this call succeeds, it must be balanced by a call to Bitmap::unlock_pixels()
, after
which time the address of the pixels should no longer be used.
sourcepub fn unlock_pixels(&self) -> Result<()>
pub fn unlock_pixels(&self) -> Result<()>
Call this to balance a successful call to Bitmap::lock_pixels()
.
sourcepub fn hardware_buffer(&self) -> Result<HardwareBufferRef>
Available on crate feature api-level-30
only.
pub fn hardware_buffer(&self) -> Result<HardwareBufferRef>
api-level-30
only.Retrieve the native object associated with an ffi::ANDROID_BITMAP_FLAGS_IS_HARDWARE
Bitmap
(requires BitmapInfoFlags::is_hardware()
on BitmapInfo::flags()
to return
true
).
Client must not modify it while a Bitmap
is wrapping it.
sourcepub fn compress<F: FnMut(&[u8]) -> Result<(), ()>>(
&self,
format: BitmapCompressFormat,
quality: i32,
compress_callback: F
) -> Result<(), BitmapCompressError>
Available on crate feature api-level-30
only.
pub fn compress<F: FnMut(&[u8]) -> Result<(), ()>>( &self, format: BitmapCompressFormat, quality: i32, compress_callback: F ) -> Result<(), BitmapCompressError>
api-level-30
only.Lock the pixels in self
and compress them as described by info()
.
Unlike compress_raw()
this requires a Bitmap
object (as self
) backed by a
jobject
.
§Parameters
format
:BitmapCompressFormat
to compress to.quality
: Hint to the compressor,0-100
. The value is interpreted differently depending onBitmapCompressFormat
.compress_callback
: Closure that writes the compressed data. Will be called on the current thread, each time the compressor has compressed more data that is ready to be written. May be called more than once for each call to this method.
sourcepub unsafe fn compress_raw<F: FnMut(&[u8]) -> Result<(), ()>>(
info: &BitmapInfo,
data_space: DataSpace,
pixels: *const c_void,
format: BitmapCompressFormat,
quality: i32,
compress_callback: F
) -> Result<(), BitmapCompressError>
Available on crate feature api-level-30
only.
pub unsafe fn compress_raw<F: FnMut(&[u8]) -> Result<(), ()>>( info: &BitmapInfo, data_space: DataSpace, pixels: *const c_void, format: BitmapCompressFormat, quality: i32, compress_callback: F ) -> Result<(), BitmapCompressError>
api-level-30
only.Compress pixels
as described by info
.
Unlike compress()
this takes a raw pointer to pixels and does not need a Bitmap
object backed by a jobject
.
§Parameters
info
: Description of the pixels to compress.data_space
:DataSpace
describing the color space of the pixels. Should not beDataSpace::Unknown
1.pixels
: Pointer to pixels to compress.format
:BitmapCompressFormat
to compress to.quality
: Hint to the compressor,0-100
. The value is interpreted differently depending onBitmapCompressFormat
.compress_callback
: Closure that writes the compressed data. Will be called on the current thread, each time the compressor has compressed more data that is ready to be written. May be called more than once for each call to this method.
§Safety
pixels
must point to a valid buffer that matches the size, stride and format in info
.