android.graphics.Bitmap.copyPixelsFromBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(334)

本文整理了Java中android.graphics.Bitmap.copyPixelsFromBuffer()方法的一些代码示例,展示了Bitmap.copyPixelsFromBuffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.copyPixelsFromBuffer()方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:copyPixelsFromBuffer

Bitmap.copyPixelsFromBuffer介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

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);
}

代码示例来源:origin: stackoverflow.com

map.position(0);
imgIn.copyPixelsFromBuffer(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: stackoverflow.com

bitmap.copyPixelsFromBuffer(intBuffer);

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: commonsguy/cw-omnibus

latestBitmap.copyPixelsFromBuffer(buffer);

代码示例来源:origin: stackoverflow.com

base.copyPixelsFromBuffer(buffOut);
blend.recycle();

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源: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: doggycoder/AndroidOpenGLDemo

@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();

代码示例来源:origin: doggycoder/AndroidOpenGLDemo

@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();

代码示例来源:origin: doggycoder/AndroidOpenGLDemo

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;
}

代码示例来源:origin: curtis2/SuperVideoPlayer

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);
  }
 }
}

代码示例来源:origin: stackoverflow.com

dst.position(0);
myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
myVideoScreenshotBm.copyPixelsFromBuffer(dst);

代码示例来源:origin: mapsforge/mapsforge

@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;
}

代码示例来源:origin: SachinVin/citra_android

@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);
 }
}

相关文章