Class ImageRef
-
- All Implemented Interfaces:
-
android.os.Parcelable
,java.lang.AutoCloseable
public final class ImageRef implements Parcelable, AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
ImageRef.Companion
-
Field Summary
Fields Modifier and Type Field Description private final UUID
uniqueId
public final static ImageRef.Companion
Companion
-
Method Summary
Modifier and Type Method Description final UUID
getUniqueId()
Unique id of the native resource the object points to. Integer
hashCode()
Boolean
equals(Object other)
final ImageRef
clone()
Creates a deep copy of the image. final Unit
hibernate()
Compresses ImageRef and stores it either on disk or in memory according to global settings. final Unit
clear()
Releases native resources stored by the ref. final ImageInfo
info()
Information about stored image. final Bitmap
toBitmap()
Returns stored image as a bitmap final Boolean
saveImage(String path, SaveImageOptions options)
Saves the stored image with the given options. final ByteArray
encodeImage(EncodeImageOptions options)
Returns the stored image encoded with the given options. Unit
close()
Releases strong reference to the image final String
serialize()
Converts ImageRef to serialized string representation with acquiring serialized reference to the native resource. final JSONObject
toJson(ImageSerializationMode imageSerializationMode)
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 final static Unit
releaseAllImages()
Releases all alive images despite any existing references. final static ImageRef
fromEncodedBuffer(ByteArray encodedBuffer, BufferImageLoadOptions options)
Creates ImageRef from encoded buffer, e.g. final static ImageRef
fromInputStream(InputStream inputStream, BufferImageLoadOptions options)
Creates ImageRef from the given input stream of encoded bytes final static ImageRef
fromPath(String path, PathImageLoadOptions options)
Creates ImageRef from the path to an image. final static ImageRef
fromBitmap(Bitmap bitmap, BasicImageLoadOptions options)
Creates ImageRef from a bitmap. final static ImageRef
fromNv21(ByteArray nv21, Integer width, Integer height, RawImageLoadOptions options)
Creates ImageRef from nv21 bytes final static ImageRef
deserialize(String source)
Creates ImageRef from serialized string representation with upgrading serialized reference to a strong one final static ImageRef
fromSerializedReference(UUID uniqueId)
final static ImageRef
fromJson(Map<String, Object> source)
final static ImageRef
fromJson(JSONObject source)
final static Unit
setHibernationJpegQuality(Integer quality)
Sets the quality of JPEG compression used to encode images when hibernating. final static Unit
setHibernationCacheDirPath(String cacheDirPath)
Sets directory in which hibernated images are stored. final static Unit
setStorageCryptingProvider(CoreStreamProvider storageCryptingProvider)
Sets storageCryptingProvider that is used when an image is read/written from/to disk. final static Boolean
acquireSerializedReference(UUID uniqueId)
final static Boolean
releaseStrongReference(UUID uniqueId)
final static Boolean
upgradeSerializedReference(UUID uniqueId)
-
-
-
Method Detail
-
getUniqueId
final UUID getUniqueId()
Unique id of the native resource the object points to.
-
hibernate
final Unit hibernate()
Compresses ImageRef and stores it either on disk or in memory according to global settings.
-
clear
final Unit clear()
Releases native resources stored by the ref. If two different ImageRef objects have the same uniqueId both of them become cleared.
-
saveImage
final Boolean saveImage(String path, SaveImageOptions options)
Saves the stored image with the given options.
-
encodeImage
final ByteArray encodeImage(EncodeImageOptions options)
Returns the stored image encoded with the given options.
-
serialize
final String serialize()
Converts ImageRef to serialized string representation with acquiring serialized reference to the native resource. You must eventually call deserialize, otherwise the reference will leak
-
toJson
final JSONObject toJson(ImageSerializationMode imageSerializationMode)
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
-
releaseAllImages
final static Unit releaseAllImages()
Releases all alive images despite any existing references.
-
fromEncodedBuffer
final static ImageRef fromEncodedBuffer(ByteArray encodedBuffer, BufferImageLoadOptions options)
Creates ImageRef from encoded buffer, e.g. from jpeg.
-
fromInputStream
final static ImageRef fromInputStream(InputStream inputStream, BufferImageLoadOptions options)
Creates ImageRef from the given input stream of encoded bytes
-
fromPath
final static ImageRef fromPath(String path, PathImageLoadOptions options)
Creates ImageRef from the path to an image.
-
fromBitmap
final static ImageRef fromBitmap(Bitmap bitmap, BasicImageLoadOptions options)
Creates ImageRef from a bitmap.
-
fromNv21
final static ImageRef fromNv21(ByteArray nv21, Integer width, Integer height, RawImageLoadOptions options)
Creates ImageRef from nv21 bytes
-
deserialize
final static ImageRef deserialize(String source)
Creates ImageRef from serialized string representation with upgrading serialized reference to a strong one
-
fromSerializedReference
final static ImageRef fromSerializedReference(UUID uniqueId)
-
fromJson
final static ImageRef fromJson(JSONObject source)
-
setHibernationJpegQuality
final static Unit setHibernationJpegQuality(Integer quality)
Sets the quality of JPEG compression used to encode images when hibernating. The default is 80.
-
setHibernationCacheDirPath
final static Unit setHibernationCacheDirPath(String cacheDirPath)
Sets directory in which hibernated images are stored. If null is passed, then hibernated images are stored in compressed format in memory. Can be set at most once, best when the application is initialized but in any case before any ImageRef is created.
-
setStorageCryptingProvider
final static Unit setStorageCryptingProvider(CoreStreamProvider storageCryptingProvider)
Sets storageCryptingProvider that is used when an image is read/written from/to disk. The provider is used both when images are hibernated and when they are saved/loaded from disk with saveImage/fromPath. Can be set at most once, best when the application is initialized but in any case before any ImageRef is created.
-
acquireSerializedReference
final static Boolean acquireSerializedReference(UUID uniqueId)
-
releaseStrongReference
final static Boolean releaseStrongReference(UUID uniqueId)
-
upgradeSerializedReference
final static Boolean upgradeSerializedReference(UUID uniqueId)
-
-