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

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

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

Bitmap.setPixel介绍

暂无

代码示例

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

@Test(expected = IllegalStateException.class)
public void shouldThrowExceptionForSetPixelOnImmutableBitmap() {
 Bitmap bitmap = Bitmap.createBitmap(new int[] { 1 }, 1, 1, Bitmap.Config.ARGB_8888);
 bitmap.setPixel(0, 0, 2);
}

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

for(int y = 0;y < bitmap.getHeight();y++)
  if(match(bitmap.getPixel(x, y))) 
    bitmap.setPixel(x, y, to);

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

@Test
public void testGetPixels() {
 // Create a dummy bitmap.
 Bitmap bmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
 for (int y = 0; y < bmp.getHeight(); ++y) {
  for (int x = 0; x < bmp.getWidth(); ++x) {
   bmp.setPixel(x, y, packRGB(x, y, 0));
  }
 }
 // Use getPixels to get pixels as an array (getPixels was the missing Shadowed Function).
 int[] pixels = new int[bmp.getWidth() * bmp.getHeight()];
 bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
 // Every entry should match regardless of accessing it by getPixel vs getPixels.
 for (int y = 0; y < bmp.getHeight(); ++y) {
  for (int x = 0; x < bmp.getWidth(); ++x) {
   assertThat(bmp.getPixel(x, y)).isEqualTo(pixels[y * bmp.getWidth() + x]);
  }
 }
}

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

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

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

@Test
public void shouldGetPixelsFromSubsetOfBitmap() {
 int width = 10;
 int height = 10;
 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
 int offset = 7;
 int subWidth = 3;
 int subHeight = 4;
 int x = 2;
 int y = 5;
 // Fill a region of the bitmap with increasing redness.
 int r = 0;
 for (int y0 = y; y0 < y + subHeight; y0++) {
  for (int x0 = x; x0 < x + subWidth; x0++) {
   bitmap.setPixel(x0, y0, packRGB(r++, 0, 0));
  }
 }
 // Get the pixels from that region.
 int[] pixels = new int[offset + subWidth * subHeight];
 bitmap.getPixels(pixels, offset, subWidth, x, y, subWidth, subHeight);
 // Verify that pixels contains the expected colors.
 r = 0;
 int index = offset;
 for (int y0 = 0; y0 < subHeight; y0++) {
  for (int x0 = 0; x0 < subWidth; x0++) {
   assertThat(pixels[index++]).isEqualTo(packRGB(r++, 0, 0));
  }
 }
}

代码示例来源:origin: ZieIony/Carbon

for (int y = 0; y < getHeight(); y++) {
  int maskPixel = mask.getPixel(x, y);
  layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0);

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

@Test
public void shouldSetPixel() {
 Bitmap bitmap = Bitmap.createBitmap(new int[] { 1 }, 1, 1, Bitmap.Config.ARGB_8888);
 shadowOf(bitmap).setMutable(true);
 bitmap.setPixel(0, 0, 2);
 assertThat(bitmap.getPixel(0, 0)).isEqualTo(2);
 assertThat(shadowOf(bitmap).getCreatedFromColors()).isEqualTo(new int[] { 1 });
}

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

@Test
public void shouldSetPixel_allocateOnTheFly() {
 Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
 shadowOf(bitmap).setMutable(true);
 bitmap.setPixel(0, 0, 2);
 assertThat(bitmap.getPixel(0, 0)).isEqualTo(2);
 assertThat(shadowOf(bitmap).getCreatedFromColors()).isNull();
}

相关文章