FirebaseVisionImage

public class FirebaseVisionImage extends Object

Represents an image object that can be used for both on-device and cloud API detectors.

Public Method Summary

static FirebaseVisionImage
fromBitmap(Bitmap bitmap)
Creates a FirebaseVisionImage from a Bitmap, where the object in the image should be already up-right and no rotation is needed.
static FirebaseVisionImage
fromByteArray(byte[] byteArray, FirebaseVisionImageMetadata metadata)
Creates a FirebaseVisionImage from a byte array, e.g.
static FirebaseVisionImage
static FirebaseVisionImage
fromFilePath(Context context, Uri imageUri)
Creates a FirebaseVisionImage from a local image file Uri.
static FirebaseVisionImage
fromMediaImage(Image image, int rotation)
Creates a FirebaseVisionImage from a Image object, e.g.
Bitmap
getBitmap()
Returns its bitmap representation.

Inherited Method Summary

Object
clone()
boolean
equals(Object arg0)
void
finalize()
final Class<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()

Public Methods

public static FirebaseVisionImage fromBitmap (Bitmap bitmap)

Creates a FirebaseVisionImage from a Bitmap, where the object in the image should be already up-right and no rotation is needed.

public static FirebaseVisionImage fromByteArray (byte[] byteArray, FirebaseVisionImageMetadata metadata)

Creates a FirebaseVisionImage from a byte array, e.g. what you get from Camera callback.

public static FirebaseVisionImage fromByteBuffer (ByteBuffer byteBuffer, FirebaseVisionImageMetadata metadata)

Creates a FirebaseVisionImage from a ByteBuffer.

We assume the entire buffer from position zero to its limit is all image data.

public static FirebaseVisionImage fromFilePath (Context context, Uri imageUri)

Creates a FirebaseVisionImage from a local image file Uri.

Throws
IOException if the image could not be retrieved from the specified imageUri. This could happen even if the Uri came from content chooser, e.g. some users might have content providers for remote resources.

public static FirebaseVisionImage fromMediaImage (Image image, int rotation)

Creates a FirebaseVisionImage from a Image object, e.g. what you obtained from android.hardware.camera2 API.

Note that we only support JPEG / YUV_420_888 formats at this moment. If you are using cloud vision detectors, JPEG format is recommended; if you are using on-device detectors, YUV_420_888 will be more efficient.

After you get back a FirebaseVisionImage, it's safe to close the input Image.

Parameters
image
rotation The camera rotation, e.g. ROTATION_90 for back camera landscape mode. See also FirebaseVisionImageMetadata.Rotation.

public Bitmap getBitmap ()

Returns its bitmap representation.

The image will be rotated to up-right if it's created with rotation info via setRotation(int).

Firebase ML lets you add powerful machine learning features to your app with ready-to-use APIs and support for custom model deployment.

Updated Feb 21, 2025

Use machine learning in your apps to solve real-world problems.

Updated Feb 20, 2025

ML Kit for Firebase provided ready-to-use ML solutions for app developers. New apps should use the standalone ML Kit library for on-device ML and Firebase ML for cloud-based ML.

Updated Feb 20, 2025