Class CameraFrame
java.lang.Object
com.codename1.camera.CameraFrame
A single frame delivered to a FrameListener.
Lifetime: the byte arrays returned by this class are valid only while
FrameListener#onFrame(CameraFrame) is on the stack. After it returns the
framework may reuse or release the underlying buffers. Clone any data you
need to keep.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceEncodes a frame on demand. -
Constructor Summary
ConstructorsConstructorDescriptionCameraFrame(byte[] jpegBytes, byte[] rawBytes, int width, int height, int rotationDegrees, long timestampNanos, FrameFormat format) Used by platform implementations.CameraFrame(byte[] jpegBytes, byte[] rawBytes, int width, int height, int rotationDegrees, long timestampNanos, FrameFormat format, CameraFrame.JpegEncoder jpegEncoder) Used by ports that can supply raw frames without eagerly encoding JPEG. -
Method Summary
Modifier and TypeMethodDescriptionPixel format requested for this frame.intPixel height of the frame.byte[]JPEG-encoded bytes for this frame.byte[]Raw pixel bytes in the format requested viaCameraSessionOptions#frameFormat(FrameFormat).intClockwise rotation in degrees (0, 90, 180, 270) that should be applied to the bytes to display them upright.longMonotonic timestamp in nanoseconds.intgetWidth()Pixel width of the frame.
-
Constructor Details
-
CameraFrame
public CameraFrame(byte[] jpegBytes, byte[] rawBytes, int width, int height, int rotationDegrees, long timestampNanos, FrameFormat format) Used by platform implementations. -
CameraFrame
public CameraFrame(byte[] jpegBytes, byte[] rawBytes, int width, int height, int rotationDegrees, long timestampNanos, FrameFormat format, CameraFrame.JpegEncoder jpegEncoder) Used by ports that can supply raw frames without eagerly encoding JPEG. The encoder is invoked at most once after a successful encoding, when#getJpegBytes()is first called. Existing eager callers need no encoder.
-
-
Method Details
-
getJpegBytes
public byte[] getJpegBytes()JPEG-encoded bytes for this frame. Always non-null regardless of the requestedFrameFormat; use this when encoded image data is needed.VisionImage#fromCameraFrame(CameraFrame)instead selects the raw buffer for NV21 and RGBA8888 frames. A raw frame may encode its JPEG lazily on the first call; subsequent calls return the cached bytes. -
getRawBytes
public byte[] getRawBytes()Raw pixel bytes in the format requested viaCameraSessionOptions#frameFormat(FrameFormat). This isnullfor JPEG requests and may also benullwhen the current port cannot expose the requested raw format. In that casegetJpegBytes()remains available as a fallback. -
getWidth
public int getWidth()Pixel width of the frame. -
getHeight
public int getHeight()Pixel height of the frame. -
getRotationDegrees
public int getRotationDegrees()Clockwise rotation in degrees (0, 90, 180, 270) that should be applied to the bytes to display them upright. -
getTimestampNanos
public long getTimestampNanos()Monotonic timestamp in nanoseconds. Useful for measuring inter-frame intervals. -
getFormat
Pixel format requested for this frame. A non-JPEG value describesgetRawBytes()when that buffer is available; ports that cannot expose raw pixels may returnnullthere while still reporting the requested format. JPEG bytes returned bygetJpegBytes()are always JPEG-encoded regardless of this value.
-