Buffer Class

Description

Buffer 存储了原始字节数组,可以用来访问图像数据。

在Java API中可以从 Image 中获取buffer然后copy数据到Java字节数组。

在EasyAR Sense的所有版本中,你都可以访问图像数据。参考 Image

wrap

包装一个指定长度的原始内存块。在Buffer被完全释放的时候,会调用deleter回调,执行用户自定义内存销毁行为。deleter必须是线程安全的。

C

void easyar_Buffer_wrap(void * ptr, int size, easyar_FunctorOfVoid deleter, easyar_Buffer * * Return)

C++

static std::shared_ptr<Buffer> wrap(void * ptr, int size, std::function<void()> deleter)

Java

public static @Nonnull Buffer wrap(long ptr, int size, @Nonnull FunctorOfVoid deleter)

Kotlin

companion object fun wrap(ptr: Long, size: Int, deleter: FunctorOfVoid): Buffer

Objective-C

+ (easyar_Buffer *)wrap:(void *)ptr size:(int)size deleter:(void (^)())deleter

Swift

public static func wrap(_ ptr: OpaquePointer?, _ size: Int32, _ deleter: @escaping () -> Void) -> Buffer

C#

public static Buffer wrap(IntPtr ptr, int size, Action deleter)

create

创建一个指定字节长度的Buffer。

C

void easyar_Buffer_create(int size, easyar_Buffer * * Return)

C++

static std::shared_ptr<Buffer> create(int size)

Java

public static @Nonnull Buffer create(int size)

Kotlin

companion object fun create(size: Int): Buffer

Objective-C

+ (easyar_Buffer *)create:(int)size

Swift

public static func create(_ size: Int32) -> Buffer

C#

public static Buffer create(int size)

data

返回原始内存地址。

C

void * easyar_Buffer_data(const easyar_Buffer * This)

C++

void * data()

Java

public long data()

Kotlin

fun data(): Long

Objective-C

- (void *)data

Swift

public func data() -> OpaquePointer?

C#

public virtual IntPtr data()

size

Buffer的字节长度。

C

int easyar_Buffer_size(const easyar_Buffer * This)

C++

int size()

Java

public int size()

Kotlin

fun size(): Int

Objective-C

- (int)size

Swift

public func size() -> Int32

C#

public virtual int size()

memoryCopy

复制原始内存。主要用于内存操作不完善的语言或环境。

C

void easyar_Buffer_memoryCopy(void * src, void * dest, int length)

C++

static void memoryCopy(void * src, void * dest, int length)

Java

public static void memoryCopy(long src, long dest, int length)

Kotlin

companion object fun memoryCopy(src: Long, dest: Long, length: Int): Unit

Objective-C

+ (void)memoryCopy:(void *)src dest:(void *)dest length:(int)length

Swift

public static func memoryCopy(_ src: OpaquePointer?, _ dest: OpaquePointer?, _ length: Int32) -> Void

C#

public static void memoryCopy(IntPtr src, IntPtr dest, int length)

tryCopyFrom

尝试从原始内存地址复制数据到Buffer中。如果复制成功,则返回true,否则返回false。失败的原因有:源数据范围或目标数据范围超出可用范围。

C

bool easyar_Buffer_tryCopyFrom(easyar_Buffer * This, void * src, int srcIndex, int index, int length)

C++

bool tryCopyFrom(void * src, int srcIndex, int index, int length)

Java

public boolean tryCopyFrom(long src, int srcIndex, int index, int length)

Kotlin

fun tryCopyFrom(src: Long, srcIndex: Int, index: Int, length: Int): Boolean

Objective-C

- (bool)tryCopyFrom:(void *)src srcIndex:(int)srcIndex index:(int)index length:(int)length

Swift

public func tryCopyFrom(_ src: OpaquePointer?, _ srcIndex: Int32, _ index: Int32, _ length: Int32) -> Bool

C#

public virtual bool tryCopyFrom(IntPtr src, int srcIndex, int index, int length)

tryCopyTo

尝试从Buffer复制数据到原始内存地址中。如果复制成功,则返回true,否则返回false。失败的原因有:源数据范围或目标数据范围超出可用范围。

C

bool easyar_Buffer_tryCopyTo(easyar_Buffer * This, int index, void * dest, int destIndex, int length)

C++

bool tryCopyTo(int index, void * dest, int destIndex, int length)

Java

public boolean tryCopyTo(int index, long dest, int destIndex, int length)

Kotlin

fun tryCopyTo(index: Int, dest: Long, destIndex: Int, length: Int): Boolean

Objective-C

- (bool)tryCopyTo:(int)index dest:(void *)dest destIndex:(int)destIndex length:(int)length

Swift

public func tryCopyTo(_ index: Int32, _ dest: OpaquePointer?, _ destIndex: Int32, _ length: Int32) -> Bool

C#

public virtual bool tryCopyTo(int index, IntPtr dest, int destIndex, int length)

partition

创建一个子Buffer,并引用原Buffer。一个Buffer在所有子Buffer释放后才会释放。

C

void easyar_Buffer_partition(easyar_Buffer * This, int index, int length, easyar_Buffer * * Return)

C++

std::shared_ptr<Buffer> partition(int index, int length)

Java

public @Nonnull Buffer partition(int index, int length)

Kotlin

fun partition(index: Int, length: Int): Buffer

Objective-C

- (easyar_Buffer *)partition:(int)index length:(int)length

Swift

public func partition(_ index: Int32, _ length: Int32) -> Buffer

C#

public virtual Buffer partition(int index, int length)

wrapByteArray

包装一个字节数组。可以指定起始位置和长度,可以指定Buffer是只读还是可读写(只读Buffer释放可能更快)。可以指定deleter回调,在Buffer被完全释放的时候,会调用deleter回调,执行用户自定义内存销毁行为。deleter必须是线程安全的。

Java

public static @Nonnull Buffer wrapByteArray(byte @Nonnull[] bytes)

public static @Nonnull Buffer wrapByteArray(byte @Nonnull[] bytes, int index, int length, boolean readOnly, @Nonnull FunctorOfVoid deleter)

Kotlin

companion object fun wrapByteArray(bytes: Array<Byte>): Buffer

companion object fun wrapByteArray(bytes: Array<Byte>, index: Int, length: Int, readOnly: Boolean, deleter: FunctorOfVoid): Buffer

C#

public static Buffer wrapByteArray(byte[] bytes)

public static Buffer wrapByteArray(byte[] bytes, int index, int length)

public static Buffer wrapByteArray(byte[] bytes, int index, int length, Action deleter)

wrapBuffer

包装一个java.nio.Buffer。可以指定deleter回调,在Buffer被完全释放的时候,会调用deleter回调,执行用户自定义内存销毁行为。deleter必须是线程安全的。

Java

public static @Nonnull Buffer wrapBuffer(java.nio.@Nonnull Buffer directBuffer)

public static @Nonnull Buffer wrapBuffer(java.nio.@Nonnull Buffer directBuffer, @Nonnull FunctorOfVoid deleter)

Kotlin

companion object fun wrapBuffer(directBuffer: java.nio.Buffer): Buffer

companion object fun wrapBuffer(directBuffer: java.nio.Buffer, deleter: FunctorOfVoid): Buffer

copyFromByteArray

从字节数组复制数据到Buffer中。如果复制失败,则抛出异常。失败的原因有:源数据范围或目标数据范围超出可用范围。

Java

public void copyFromByteArray(byte @Nonnull[] src)

public void copyFromByteArray(byte @Nonnull[] src, int srcIndex, int index, int length)

Kotlin

fun copyFromByteArray(src: Array<Byte>): Unit

fun copyFromByteArray(src: Array<Byte>, srcIndex: Int, index: Int, length: Int): Unit

C#

public void copyFromByteArray(byte[] src)

public void copyFromByteArray(byte[] src, int srcIndex, int index, int length)

copyToByteArray

从Buffer复制数据到字节数组中。如果复制失败,则抛出异常。失败的原因有:源数据范围或目标数据范围超出可用范围。

Java

public void copyToByteArray(byte @Nonnull[] dest)

public void copyToByteArray(int index, byte @Nonnull[] dest, int destIndex, int length)

Kotlin

fun copyToByteArray(dest: Array<Byte>): Unit

fun copyToByteArray(index: Int, dest: Array<Byte>, destIndex: Int, length: Int): Unit

C#

public void copyToByteArray(byte[] dest)

public void copyToByteArray(int index, byte[] dest, int destIndex, int length)

tryCopyFromByteArray

从字节数组复制数据到Buffer中。如果复制成功,则返回true,否则返回false。失败的原因有:源数据范围或目标数据范围超出可用范围。

Swift

public func tryCopyFromByteArray(_ src: [UInt8]) -> Bool

public func tryCopyFromByteArray(_ src: [UInt8], _ srcIndex: Int32, _ index: Int32, _ length: Int32) -> Bool

tryCopyToByteArray

从Buffer复制数据到字节数组中。如果复制成功,则返回true,否则返回false。失败的原因有:源数据范围或目标数据范围超出可用范围。

Swift

public func tryCopyToByteArray(_ dest: [UInt8]) -> Bool

public func tryCopyToByteArray(_ index: Int32, _ dest: [UInt8], _ destIndex: Int32, _ length: Int32) -> Bool