本文整理了Java中android.graphics.Bitmap.copyPixelsToBuffer()
方法的一些代码示例,展示了Bitmap.copyPixelsToBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.copyPixelsToBuffer()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:copyPixelsToBuffer
暂无
代码示例来源:origin: Rajawali/Rajawali
public void setBitmap(Bitmap bitmap) {
mBitmap = bitmap;
int imageSize = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize);
bitmap.copyPixelsToBuffer(uncompressedBuffer);
uncompressedBuffer.position(0);
ByteBuffer compressedBuffer = ByteBuffer.allocateDirect(
ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder());
ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(),
compressedBuffer);
mByteBuffers = new ByteBuffer[]{compressedBuffer};
setWidth(bitmap.getWidth());
setHeight(bitmap.getHeight());
}
代码示例来源:origin: Rajawali/Rajawali
private void setBitmap(Bitmap bitmap) {
mBitmap = bitmap;
int imageSize = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize);
bitmap.copyPixelsToBuffer(uncompressedBuffer);
uncompressedBuffer.position(0);
ByteBuffer compressedBuffer = ByteBuffer.allocateDirect(
ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder());
ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(),
compressedBuffer);
setCompressionFormat(ETC1.ETC1_RGB8_OES);
mByteBuffers = new ByteBuffer[]{compressedBuffer};
setWidth(bitmap.getWidth());
setHeight(bitmap.getHeight());
}
}
代码示例来源:origin: stackoverflow.com
imgIn.copyPixelsToBuffer(map);
代码示例来源:origin: stackoverflow.com
if(screenshot){
int screenshotSize = width * height;
ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4);
bb.order(ByteOrder.nativeOrder());
gl.glReadPixels(0, 0, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
int pixelsBuffer[] = new int[screenshotSize];
bb.asIntBuffer().get(pixelsBuffer);
bb = null;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
bitmap.setPixels(pixelsBuffer, screenshotSize-width, -width, 0, 0, width, height);
pixelsBuffer = null;
short sBuffer[] = new short[screenshotSize];
ShortBuffer sb = ShortBuffer.wrap(sBuffer);
bitmap.copyPixelsToBuffer(sb);
//Making created bitmap (from OpenGL points) compatible with Android bitmap
for (int i = 0; i < screenshotSize; ++i) {
short v = sBuffer[i];
sBuffer[i] = (short) (((v&0x1f) << 11) | (v&0x7e0) | ((v&0xf800) >> 11));
}
sb.rewind();
bitmap.copyPixelsFromBuffer(sb);
lastScreenshot = bitmap;
screenshot = false;
}
代码示例来源:origin: robolectric/robolectric
@Test(expected = RuntimeException.class)
public void throwsExceptionCopyPixelsToBufferTooSmall() {
Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
ByteBuffer buffer = ByteBuffer.allocate(bitmapOriginal.getByteCount() - 1);
bitmapOriginal.copyPixelsToBuffer(buffer);
}
代码示例来源:origin: robolectric/robolectric
@Test(expected = RuntimeException.class)
public void throwsExceptionCopyPixelsToBufferNonArgb8888() {
Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_4444);
ByteBuffer buffer = ByteBuffer.allocate(bitmapOriginal.getByteCount());
bitmapOriginal.copyPixelsToBuffer(buffer);
}
代码示例来源:origin: facebook/facebook-android-sdk
private static void compareImages(Bitmap bmp1, Bitmap bmp2) {
assertTrue(bmp1.getHeight() == bmp2.getHeight());
assertTrue(bmp1.getWidth() == bmp1.getWidth());
ByteBuffer buffer1 = ByteBuffer.allocate(bmp1.getHeight() * bmp1.getRowBytes());
bmp1.copyPixelsToBuffer(buffer1);
ByteBuffer buffer2 = ByteBuffer.allocate(bmp2.getHeight() * bmp2.getRowBytes());
bmp2.copyPixelsToBuffer(buffer2);
assertTrue(Arrays.equals(buffer1.array(), buffer2.array()));
}
代码示例来源:origin: stackoverflow.com
base.copyPixelsToBuffer(buffBase);
buffBase.rewind();
blend.copyPixelsToBuffer(buffBlend);
buffBlend.rewind();
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
bitmap.copyPixelsToBuffer(data);
代码示例来源:origin: robolectric/robolectric
@Test(expected = RuntimeException.class)
public void throwsExceptionCopyPixelsToLongBuffer() {
Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
LongBuffer buffer = LongBuffer.allocate(bitmapOriginal.getByteCount());
bitmapOriginal.copyPixelsToBuffer(buffer);
}
代码示例来源:origin: robolectric/robolectric
@Test(expected = RuntimeException.class)
public void throwsExceptionCopyPixelsToShortBuffer() {
Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
ShortBuffer buffer = ShortBuffer.allocate(bitmapOriginal.getByteCount());
bitmapOriginal.copyPixelsToBuffer(buffer);
}
代码示例来源:origin: robolectric/robolectric
@Test(expected = RuntimeException.class)
public void throwsExceptionCopyPixelsToIntBuffer() {
Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
IntBuffer buffer = IntBuffer.allocate(bitmapOriginal.getByteCount());
bitmapOriginal.copyPixelsToBuffer(buffer);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldCopyPixelsToBufferAndReconstruct() {
int width = 10;
int height = 10;
Bitmap bitmapOriginal = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmapOriginal.setPixel(0, 0, 123);
bitmapOriginal.setPixel(1, 1, 456);
bitmapOriginal.setPixel(2, 2, 789);
int[] pixelsOriginal = new int[width * height];
bitmapOriginal.getPixels(pixelsOriginal, 0, width, 0, 0, width, height);
ByteBuffer buffer = ByteBuffer.allocate(bitmapOriginal.getByteCount());
bitmapOriginal.copyPixelsToBuffer(buffer);
assertThat(buffer.position()).isEqualTo(bitmapOriginal.getByteCount());
buffer.rewind();
Bitmap bitmapReconstructed = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// Set some random pixels to ensure that they're properly overwritten.
bitmapReconstructed.setPixel(1,1, 999);
bitmapReconstructed.setPixel(4,4, 999);
bitmapReconstructed.copyPixelsFromBuffer(buffer);
assertThat(buffer.position()).isEqualTo(bitmapOriginal.getByteCount());
assertThat(bitmapReconstructed.getPixel(0, 0)).isEqualTo(123);
assertThat(bitmapReconstructed.getPixel(1, 1)).isEqualTo(456);
assertThat(bitmapReconstructed.getPixel(2, 2)).isEqualTo(789);
int[] pixelsReconstructed = new int[width * height];
bitmapReconstructed.getPixels(pixelsReconstructed, 0, width, 0, 0, width, height);
assertThat(Arrays.equals(pixelsOriginal, pixelsReconstructed)).isTrue();
}
代码示例来源:origin: stackoverflow.com
public boolean equals(Bitmap bitmap1, Bitmap bitmap2) {
ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight() * bitmap1.getRowBytes());
bitmap1.copyPixelsToBuffer(buffer1);
ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight() * bitmap2.getRowBytes());
bitmap2.copyPixelsToBuffer(buffer2);
return Arrays.equals(buffer1.array(), buffer2.array());
}
代码示例来源:origin: stackoverflow.com
myVideoScreenshotBm.copyPixelsToBuffer(dst);
if(bytesar==null || bmSize > bytesar.length)
bytesar=new byte[bmSize];
代码示例来源:origin: stackoverflow.com
int inputPixel = 0x336699cc;
int[] pixels = new int[] { inputPixel };
Bitmap bm = Bitmap.createBitmap(pixels, 1, 1, Config.ARGB_8888);
ByteBuffer bb = ByteBuffer.allocate(4);
bm.copyPixelsToBuffer(bb);
Log.i("TAG", "inputPixel = 0x" + Integer.toHexString(inputPixel));
for (int i = 0; i < 4; i++) {
String byteString = "0x" + Integer.toHexString(bb.array()[i] & 0xff);
Log.i("TAG", "outputPixel byte " + i + " = " + byteString);
}
代码示例来源:origin: stackoverflow.com
protected long saveBitmap(SQLiteDatabase database, Bitmap bmp)
{
int size = bmp.getRowBytes() * bmp.getHeight();
ByteBuffer b = ByteBuffer.allocate(size); bmp.copyPixelsToBuffer(b);
byte[] bytes = new byte[size];
b.get(bytes, 0, bytes.length);
ContentValues cv=new ContentValues();
cv.put(CHUNK, bytes);
this.id= database.insert(TABLE, null, cv);
}
代码示例来源:origin: PrivacyApps/document-viewer
public static ByteBufferBitmap get(final Bitmap bmp) {
if (bmp.getConfig() != Bitmap.Config.ARGB_8888) {
throw new IllegalArgumentException("Wrong bitmap config: " + bmp.getConfig());
}
final ByteBufferBitmap b = ByteBufferManager.getBitmap(bmp.getWidth(), bmp.getHeight());
bmp.copyPixelsToBuffer(b.pixels);
return b;
}
代码示例来源:origin: stackoverflow.com
...
Bitmap b = ...
int bytes = b.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes);
b.copyPixelsToBuffer(buffer); //Move the byte data to the buffer
byte[] data = buffer.array(); //Get the bytes array of the bitmap
YuvImage yuv = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null);
代码示例来源:origin: stackoverflow.com
ByteBuffer copyToBuffer(Bitmap bitmap){
int size = bitmap.getHeight() * bitmap.getRowBytes();
ByteBuffer buffer = ByteBuffer.allocateDirect(size);
bitmap.copyPixelsToBuffer(buffer);
return buffer;
}
内容来源于网络,如有侵权,请联系作者删除!