Java FloatBuffer to Array floatArrayToFloatBuffer(float[] data)

Here you can find the source of floatArrayToFloatBuffer(float[] data)

Description

Converts an array of primitive floats to a java.nio.FloatBuffer .

License

Open Source License

Parameter

Parameter Description
data The float array to convert.

Return

Returns the form of the float array.

Declaration

public static FloatBuffer floatArrayToFloatBuffer(float[] data) 

Method Source Code

//package com.java2s;
/**/*  w  ww. ja  va2s . c  o m*/
 * The MIT License (MIT)
 * Wrath Utils Copyright (c) 2016 Trent Spears
 */

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

public class Main {
    /**
     * Converts an array of primitive floats to a {@link java.nio.FloatBuffer}.
     * @param data The float array to convert.
     * @return Returns the {@link java.nio.FloatBuffer} form of the float array.
     */
    public static FloatBuffer floatArrayToFloatBuffer(float[] data) {
        FloatBuffer ret = ByteBuffer.allocateDirect(data.length << 2).order(ByteOrder.nativeOrder())
                .asFloatBuffer();
        ret.put(data).flip();
        return ret;
    }
}

Related

  1. convertFloatBufferToArray(java.nio.FloatBuffer buf)
  2. floatBufferToHistogram(FloatBuffer ib, int width, int height, int widthStep, float[] histogram)
  3. floatBufferToString(FloatBuffer buffer)
  4. getFloatArray(final FloatBuffer buff)
  5. getFloatArray(FloatBuffer buff)