Struct ndk::bitmap::Bitmap

source ·
pub struct Bitmap { /* private fields */ }
Available on crate feature bitmap only.
Expand description

An immediate wrapper over android.graphics.Bitmap

Implementations§

source§

impl Bitmap

source

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.

source

pub fn info(&self) -> Result<BitmapInfo>

Fills out and returns the BitmapInfo struct for the given Java bitmap object.

source

pub fn data_space(&self) -> DataSpace

Available on crate feature 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.

source

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.

source

pub fn unlock_pixels(&self) -> Result<()>

Call this to balance a successful call to Bitmap::lock_pixels().

source

pub fn hardware_buffer(&self) -> Result<HardwareBufferRef>

Available on crate feature 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.

source

pub fn compress<F: FnMut(&[u8]) -> Result<(), ()>>( &self, format: BitmapCompressFormat, quality: i32, compress_callback: F ) -> Result<(), BitmapCompressError>

Available on crate feature 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 on BitmapCompressFormat.
  • 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.
source

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>

Available on crate feature 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 be DataSpace::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 on BitmapCompressFormat.
  • 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.

Trait Implementations§

source§

impl Debug for Bitmap

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Bitmap

§

impl RefUnwindSafe for Bitmap

§

impl !Send for Bitmap

§

impl !Sync for Bitmap

§

impl Unpin for Bitmap

§

impl UnwindSafe for Bitmap

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.