private void renderRgbFrame(VpxOutputBuffer outputBuffer, boolean scale) { if (bitmap == null || bitmap.getWidth() != outputBuffer.width || bitmap.getHeight() != outputBuffer.height) { bitmap = Bitmap.createBitmap(outputBuffer.width, outputBuffer.height, Bitmap.Config.RGB_565); } bitmap.copyPixelsFromBuffer(outputBuffer.data); Canvas canvas = surface.lockCanvas(null); if (scale) { canvas.scale( ((float) canvas.getWidth()) / outputBuffer.width, ((float) canvas.getHeight()) / outputBuffer.height); } canvas.drawBitmap(bitmap, 0, 0, null); surface.unlockCanvasAndPost(canvas); }
map.position(0); imgIn.copyPixelsFromBuffer(map);
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; }
bitmap.copyPixelsFromBuffer(intBuffer);
@Test(expected = IllegalStateException.class) public void throwsExceptionCopyPixelsFromBufferRecycled() { Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888); ByteBuffer buffer = ByteBuffer.allocate(bitmapOriginal.getByteCount()); bitmapOriginal.recycle(); bitmapOriginal.copyPixelsFromBuffer(buffer); }
@Test(expected = RuntimeException.class) public void throwsExceptionCopyPixelsFromBufferTooSmall() { Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888); ByteBuffer buffer = ByteBuffer.allocate(bitmapOriginal.getByteCount() - 1); bitmapOriginal.copyPixelsFromBuffer(buffer); }
@Test(expected = RuntimeException.class) public void throwsExceptionCopyPixelsFromBufferNonArgb8888() { Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_4444); ByteBuffer buffer = ByteBuffer.allocate(bitmapOriginal.getByteCount()); bitmapOriginal.copyPixelsFromBuffer(buffer); }
latestBitmap.copyPixelsFromBuffer(buffer);
base.copyPixelsFromBuffer(buffOut); blend.recycle();
@Test(expected = RuntimeException.class) public void throwsExceptionCopyPixelsFromLongBuffer() { Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888); LongBuffer buffer = LongBuffer.allocate(bitmapOriginal.getByteCount()); bitmapOriginal.copyPixelsFromBuffer(buffer); }
@Test(expected = RuntimeException.class) public void throwsExceptionCopyPixelsFromIntBuffer() { Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888); IntBuffer buffer = IntBuffer.allocate(bitmapOriginal.getByteCount()); bitmapOriginal.copyPixelsFromBuffer(buffer); }
@Test(expected = RuntimeException.class) public void throwsExceptionCopyPixelsFromShortBuffer() { Bitmap bitmapOriginal = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888); ShortBuffer buffer = ShortBuffer.allocate(bitmapOriginal.getByteCount()); bitmapOriginal.copyPixelsFromBuffer(buffer); }
@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(); }
@Override public void run() { Log.e("wuwang","callback success"); Bitmap bitmap=Bitmap.createBitmap(mBmpWidth,mBmpHeight, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(data); saveBitmap(bitmap); data.clear(); } }).start();
@Override public void run() { Bitmap bitmap=Bitmap.createBitmap(720,1280, Bitmap.Config.ARGB_8888); ByteBuffer b=ByteBuffer.wrap(bytes); bitmap.copyPixelsFromBuffer(b); saveBitmap(bitmap); bitmap.recycle(); } }).start();
private Bitmap convertToBitmap() { int[] iat = new int[mWidth * mHeight]; IntBuffer ib = IntBuffer.allocate(mWidth * mHeight); mEGLHelper.mGL.glReadPixels(0, 0, mWidth, mHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib); int[] ia = ib.array(); // Convert upside down mirror-reversed image to right-side up normal // image. for (int i = 0; i < mHeight; i++) { System.arraycopy(ia, i * mWidth, iat, (mHeight - i - 1) * mWidth, mWidth); } Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(IntBuffer.wrap(iat)); return bitmap; }
private void surfaceRender() { synchronized (this) { if (mLocalSurface == null || !mLocalSurface.isValid() || mBitmap == null || mByteBuffer == null) return; try { Canvas c = mLocalSurface.lockCanvas(null); mBitmap.copyPixelsFromBuffer(mByteBuffer); c.drawBitmap(mBitmap, 0, 0, null); mLocalSurface.unlockCanvasAndPost(c); } catch (Exception e) { Log.e("surfaceRender", e); } } }
dst.position(0); myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); myVideoScreenshotBm.copyPixelsFromBuffer(dst);
@Override public AndroidHillshadingBitmap createMonoBitmap(int width, int height, byte[] buffer, int padding, BoundingBox area) { AndroidHillshadingBitmap androidBitmap = new AndroidHillshadingBitmap(width + 2 * padding, height + 2 * padding, padding, area); if (buffer != null) { Buffer b = ByteBuffer.wrap(buffer); androidBitmap.bitmap.copyPixelsFromBuffer(b); } return androidBitmap; }
@Override public Result load(Request request, int networkPolicy) { String url = request.uri.getHost() + request.uri.getPath(); int[] vector = NativeLibrary.GetBanner(url); int width = 48; int height = 48; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); bitmap.copyPixelsFromBuffer(IntBuffer.wrap(vector)); return new Result(bitmap, Picasso.LoadedFrom.DISK); } }