make Float Buffer : Buffer « File « Android






make Float Buffer

 
//package min3d;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;


public class Utils 
{
  public static final float DEG = (float)(Math.PI / 180f);
    
  private static final int BYTES_PER_FLOAT = 4;  
  
  /**
   * Convenience method to create a Bitmap given a Context's drawable resource ID. 
   */
  public static Bitmap makeBitmapFromResourceId(Context $context, int $id)
  {
    InputStream is = $context.getResources().openRawResource($id);
    
    Bitmap bitmap;
    try {
       bitmap = BitmapFactory.decodeStream(is);
    } finally {
       try {
          is.close();
       } catch(IOException e) {
          // Ignore.
       }
    }
        
    return bitmap;
  }
  
  public static FloatBuffer makeFloatBuffer3(float $a, float $b, float $c)
  {
    ByteBuffer b = ByteBuffer.allocateDirect(3 * BYTES_PER_FLOAT);
    b.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = b.asFloatBuffer();
    buffer.put($a);
    buffer.put($b);
    buffer.put($c);
    buffer.position(0);
    return buffer;
  }

  public static FloatBuffer makeFloatBuffer4(float $a, float $b, float $c, float $d)
  {
    ByteBuffer b = ByteBuffer.allocateDirect(4 * BYTES_PER_FLOAT);
    b.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = b.asFloatBuffer();
    buffer.put($a);
    buffer.put($b);
    buffer.put($c);
    buffer.put($d);
    buffer.position(0);
    return buffer;
  }
}

   
  








Related examples in the same category

1.Fast Float Buffer
2.Demonstrate the Frame Buffer Object OpenGL ES extension.
3.Loads a file to a ByteBuffer.
4.Make a direct NIO FloatBuffer from an array of floats
5.Make a direct NIO ByteBuffer from an array of bytes
6.Make Float Buffer From Array
7.Creates a floatbuffer of the given size.
8.Make Float Buffer with ByteBuffer.allocateDirect
9.allocate Float Buffer
10.to Short Buffer
11.to Float Buffer Position Zero
12.allocate Short Buffer
13.allocate Int Buffer
14.Read InputStream with BufferedReader
15.To convert the InputStream to String we use the BufferedReader.readLine() method.
16.get Buffer From Array
17.Your own float buffer
18.Direct Buffer
19.create Buffer
20.Write String to File with BufferWriter
21.Byte Buffer Stack
22.Compute the SHA-1 hash of the bytes in the given buffer
23.An utility class for java.nio.Buffers