get direct Float Buffer From Float Array - Android java.nio

Android examples for java.nio:FloatBuffer

Description

get direct Float Buffer From Float Array

Demo Code


//package com.java2s;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Main {
    public static FloatBuffer directFloatBufferFromFloatArray(float[] data) {
        FloatBuffer buffer = null;

        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * 4);

        byteBuffer.order(ByteOrder.nativeOrder());

        buffer = byteBuffer.asFloatBuffer();
        buffer.put(data);/*from  w  w  w  . j  av a 2  s .c o  m*/
        buffer.position(0);

        return buffer;
    }
}

Related Tutorials