Buffer Class


(since 2.1.0) Buffer stores raw byte array, used to access data from Image.

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

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.


Returns raw data as a byte array.

C: void * easyar_Buffer_data(const easyar_Buffer * 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


Byte size of raw data.

C: int easyar_Buffer_size(const easyar_Buffer * This)
C++11: int size()
Traditional C++: int size()
Java: public native int size()
Objective-C: - (int)size
Swift (since EasyAR SDK 2.1.0): public func size() -> Int32


Copy buffer data to user array.

Java: public native void copyTo(byte[] data, int index)