Image Class¶
Description¶
Image stores an image data and represents an image in memory.
Image raw data can be accessed as byte array. The width/height/stride information are also accessible.
(since 2.1.0) To access image data in Java API, get buffer from Image and copy to a Java byte array.
You can always access image data from the first version of EasyAR SDK, and it is even easier in EasyAR SDK 2.1.
You can do this in iOS
#import <easyar/buffer.oc.h>
#import <easyar/image.oc.h>
easyar_Frame * frame = [streamer peek];
for (easyar_Image * i in [frame images]) {
easyar_Buffer * b = [i buffer];
char * bytes = calloc([b size], 1);
memcpy(bytes, [b data], [b size]);
//TODO: use bytes here
free(bytes);
}
Or in Android (since 2.1.0)
import cn.easyar.Buffer;
import cn.easyar.Image;
Frame frame = streamer.peek();
for (Image i : frame.images()) {
Buffer b = i.buffer();
byte[] bytes = new byte[b.size()];
b.copyTo(bytes, 0);
//TODO: use bytes here
}
Before 2.1.0, you can only pass data to JNI then pass data back to Java by yourself, or you can use that data directly in C/C++ layer.
buffer¶
(since 2.1.0) Return buffer inside image. It can be used to access internal data of image.
- C: void easyar_Image_buffer(const easyar_Image * This, easyar_Buffer * * Return)¶
- Traditional C++: void buffer(Buffer * * Return)¶
- Java: public native Buffer buffer()¶
- Objective-C: - (easyar_Buffer *)buffer¶
- Swift (since EasyAR SDK 2.1.0): public func buffer() -> Buffer¶
width¶
Returns image width.
- C: int easyar_Image_width(const easyar_Image * This)¶
- C++11: int width()¶
- Traditional C++: int width()¶
- Java: public native int width()¶
- Objective-C: - (int)width¶
- Swift (since EasyAR SDK 2.1.0): public func width() -> Int32¶
height¶
Returns image height.
- C: int easyar_Image_height(const easyar_Image * This)¶
- C++11: int height()¶
- Traditional C++: int height()¶
- Java: public native int height()¶
- Objective-C: - (int)height¶
- Swift (since EasyAR SDK 2.1.0): public func height() -> Int32¶
stride¶
Returns image stride.
- C: int easyar_Image_stride(const easyar_Image * This)¶
- C++11: int stride()¶
- Traditional C++: int stride()¶
- Java: public native int stride()¶
- Objective-C: - (int)stride¶
- Swift (since EasyAR SDK 2.1.0): public func stride() -> Int32¶
format¶
Returns image format. Generally, you will get a YUV image from camera on mobile devices and BGR image from camera on desktop devices.
- C: easyar_PixelFormat easyar_Image_format(const easyar_Image * This)¶
- C++11: PixelFormat format()¶
- Traditional C++: PixelFormat format()¶
- Java: public native /* PixelFormat */ int format()¶
- Objective-C: - (easyar_PixelFormat)format¶
- Swift (since EasyAR SDK 2.1.0): public func format() -> PixelFormat¶
data¶
Returns image raw data as a byte array.
- C: void * easyar_Image_data(const easyar_Image * This)¶
- C++11: void * data()¶
- Traditional C++: void * data()¶
- Java: public native long data()¶
- Objective-C: - (void *)data¶
- Swift (since EasyAR SDK 2.1.0): public func data() -> OpaquePointer¶