本文整理汇总了Java中java.nio.IntBuffer.array方法的典型用法代码示例。如果您正苦于以下问题:Java IntBuffer.array方法的具体用法?Java IntBuffer.array怎么用?Java IntBuffer.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.IntBuffer
的用法示例。
在下文中一共展示了IntBuffer.array方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToBitmap
import java.nio.IntBuffer; //导入方法依赖的package包/类
private void convertToBitmap() {
int[] iat = new int[mWidth * mHeight];
IntBuffer ib = IntBuffer.allocate(mWidth * mHeight);
mGL.glReadPixels(0, 0, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, ib);
int[] ia = ib.array();
//Stupid !
// Convert upside down mirror-reversed image to right-side up normal
// image.
for (int i = 0; i < mHeight; i++) {
for (int j = 0; j < mWidth; j++) {
iat[(mHeight - i - 1) * mWidth + j] = ia[i * mWidth + j];
}
}
mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
mBitmap.copyPixelsFromBuffer(IntBuffer.wrap(iat));
}
示例2: bitmapToGrayscaleImage
import java.nio.IntBuffer; //导入方法依赖的package包/类
/**
* Converts a Bitmap to a GrayscaleImage.
*/
@NonNull
public GrayscaleImage bitmapToGrayscaleImage(@NonNull Bitmap bitmap) {
String stopwatchSessionId = log.startStopwatch(getStopwatchSessionId("bitmapToGrayscaleImage"));
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int size = width * height;
IntBuffer intBuffer = IntBuffer.allocate(size);
bitmap.copyPixelsToBuffer(intBuffer);
int[] buffer = intBuffer.array();
byte[] data = new byte[size];
for (int index = 0; index < size; index++) {
data[index] = (byte) (buffer[index] >> 16);
}
log.stopStopwatch(stopwatchSessionId);
return new GrayscaleImage(data, width, height);
}
示例3: capture
import java.nio.IntBuffer; //导入方法依赖的package包/类
public Bitmap capture(int width, int height) {
mPipeline.onSurfaceChanged(null, width, height);
mPipeline.startRender();
mPipeline.onDrawFrame(null);
int[] iat = new int[mWidth * mHeight];
IntBuffer ib = IntBuffer.allocate(width * height);
GLES20.glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ib);
int[] ia = ib.array();
for (int i = 0; i < mHeight; i++) {
System.arraycopy(ia, i * mWidth, iat, (mHeight - i - 1) * mWidth, mWidth);
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(IntBuffer.wrap(iat));
mPipeline.onSurfaceDestroyed();
// 释放EGL环境
mInputSurface.release();
mEgl.release();
return bitmap;
}
示例4: getScreenShot
import java.nio.IntBuffer; //导入方法依赖的package包/类
public static Bitmap getScreenShot(int width, int height){
IntBuffer pixelBuffer = IntBuffer.allocate(width * height);
GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE,
pixelBuffer);
int[] pixelMirroredArray = new int[width * height];
int[] pixelArray = pixelBuffer.array();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixelMirroredArray[(height - i - 1) * width + j] = pixelArray[i * width + j];
}
}
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
return bmp;
}
示例5: bufferOutput
import java.nio.IntBuffer; //导入方法依赖的package包/类
@Override
public void bufferOutput(IntBuffer buffer) {
int width = getWidth();
int height = getHeight();
if (width <= 0 || height <= 0) {
if (mCallback != null) {
mCallback.bitmapOutput(null);
}
return;
}
try {
int[] pixels = buffer.array();
// 方案一,使用copyPixelsFromBuffer,是方案二速度的2倍以上
Bitmap bitmap = Bitmap.createBitmap(width, height, mConfig);
bitmap.copyPixelsFromBuffer(IntBuffer.wrap(pixels));
// 方案二,手动转换像素数组
// for (int i = 0; i < pixels.length; i++) {
// // glReadPixels设置GLES20.GL_RGBA时,读取出来格式为ABGR,要转换为Bitmap需要的ARGB,同时设置Alpha值为1
// pixels[i] = (0xFF000000)
// | ((pixels[i] << 16) & 0x00FF0000)
// | (pixels[i] & (0xFF00FF00))
// | ((pixels[i] >> 16) & 0x000000FF);
// }
// Bitmap bitmap = Bitmap.createBitmap(pixels, width, height, mConfig);
if (mCallback != null) {
mCallback.bitmapOutput(bitmap);
}
} catch (OutOfMemoryError e) {
e.printStackTrace();
if (mCallback != null) {
mCallback.bitmapOutput(null);
}
}
}
示例6: toIntArray
import java.nio.IntBuffer; //导入方法依赖的package包/类
static
public int[] toIntArray(Tensor tensor){
IntBuffer intBuffer = IntBuffer.allocate(tensor.numElements());
tensor.writeTo(intBuffer);
return intBuffer.array();
}
示例7: glGetIntegerv
import java.nio.IntBuffer; //导入方法依赖的package包/类
public synchronized static int[] glGetIntegerv(int value, int size) {
final IntBuffer buffer = IntBuffer.allocate(size);
GLES10.glGetIntegerv(value, buffer);
return buffer.array();
}