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

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

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

Bitmap.setPixels介绍

暂无

代码示例

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

private Bitmap RGB565toARGB888(Bitmap img) {
  int numPixels = img.getWidth()* img.getHeight();
  int[] pixels = new int[numPixels];

  //Get JPEG pixels.  Each int is the color values for one pixel.
  img.getPixels(pixels, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());

  //Create a Bitmap of the appropriate format.
  Bitmap result = Bitmap.createBitmap(img.getWidth(), img.getHeight(), Bitmap.Config.ARGB_8888);

  //Set RGB pixels.
  result.setPixels(pixels, 0, result.getWidth(), 0, 0, result.getWidth(), result.getHeight());
  return result;
}

代码示例来源:origin: Zomato/AndroidPhotoFilters

public static Bitmap doBrightness(int value, Bitmap inputImage) {
  int width = inputImage.getWidth();
  int height = inputImage.getHeight();
  int[] pixels = new int[width * height];
  inputImage.getPixels(pixels, 0, width, 0, 0, width, height);
  NativeImageProcessor.doBrightness(pixels, value, width, height);
  inputImage.setPixels(pixels, 0, width, 0, 0, width, height);
  return inputImage;
}

代码示例来源:origin: Zomato/AndroidPhotoFilters

public static Bitmap doSaturation(Bitmap inputImage, float level) {
  int width = inputImage.getWidth();
  int height = inputImage.getHeight();
  int[] pixels = new int[width * height];
  inputImage.getPixels(pixels, 0, width, 0, 0, width, height);
  NativeImageProcessor.doSaturation(pixels, level, width, height);
  inputImage.setPixels(pixels, 0, width, 0, 0, width, height);
  return inputImage;
}

代码示例来源:origin: Zomato/AndroidPhotoFilters

public static Bitmap doContrast(float value, Bitmap inputImage) {
  int width = inputImage.getWidth();
  int height = inputImage.getHeight();
  int[] pixels = new int[width * height];
  inputImage.getPixels(pixels, 0, width, 0, 0, width, height);
  NativeImageProcessor.doContrast(pixels, value, width, height);
  inputImage.setPixels(pixels, 0, width, 0, 0, width, height);
  return inputImage;
}

代码示例来源:origin: Zomato/AndroidPhotoFilters

public static Bitmap doColorOverlay(int depth, float red, float green, float blue, Bitmap inputImage) {
  int width = inputImage.getWidth();
  int height = inputImage.getHeight();
  int[] pixels = new int[width * height];
  inputImage.getPixels(pixels, 0, width, 0, 0, width, height);
  NativeImageProcessor.doColorOverlay(pixels, depth, red, green, blue, width, height);
  inputImage.setPixels(pixels, 0, width, 0, 0, width, height);
  return inputImage;
}

代码示例来源:origin: chentao0707/SimplifyReader

public static Bitmap doBlurJniArray(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
  Bitmap bitmap;
  if (canReuseInBitmap) {
    bitmap = sentBitmap;
  } else {
    bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
  }
  if (radius < 1) {
    return (null);
  }
  int w = bitmap.getWidth();
  int h = bitmap.getHeight();
  int[] pix = new int[w * h];
  bitmap.getPixels(pix, 0, w, 0, 0, w, h);
  // Jni array calculate
  ImageBlur.blurIntArray(pix, w, h, radius);
  bitmap.setPixels(pix, 0, w, 0, 0, w, h);
  return (bitmap);
}

代码示例来源:origin: TheFinestArtist/FinestWebView-Android

public static Bitmap getColoredBitmap(@NonNull Bitmap bitmap, @ColorInt int color) {
 int alpha = Color.alpha(color);
 int red = Color.red(color);
 int green = Color.green(color);
 int blue = Color.blue(color);
 int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];
 bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
 for (int i = 0; i < pixels.length; i++) {
  int pixel = pixels[i];
  int pixelAlpha = Color.alpha(pixel);
  if (pixelAlpha != 0) {
   pixels[i] = Color.argb((int) (pixelAlpha * alpha / 256f), red, green, blue);
  }
 }
 Bitmap coloredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
 coloredBitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(),
   bitmap.getHeight());
 return coloredBitmap;
}

代码示例来源:origin: TommyLemon/APIJSON

public Bitmap renderCroppedGreyscaleBitmap() {
  int width = getWidth();
  int height = getHeight();
  int[] pixels = new int[width * height];
  byte[] yuv = yuvData;
  int inputOffset = top * dataWidth + left;

  for (int y = 0; y < height; y++) {
   int outputOffset = y * width;
   for (int x = 0; x < width; x++) {
    int grey = yuv[inputOffset + x] & 0xff;
    pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
   }
   inputOffset += dataWidth;
  }

  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
  return bitmap;
 }
}

代码示例来源:origin: Zomato/AndroidPhotoFilters

public static Bitmap applyCurves(int[] rgb, int[] red, int[] green, int[] blue, Bitmap inputImage) {
  // create output bitmap
  Bitmap outputImage = inputImage;
  // get image size
  int width = inputImage.getWidth();
  int height = inputImage.getHeight();
  int[] pixels = new int[width * height];
  outputImage.getPixels(pixels, 0, width, 0, 0, width, height);
  if (rgb != null) {
    pixels = NativeImageProcessor.applyRGBCurve(pixels, rgb, width, height);
  }
  if (!(red == null && green == null && blue == null)) {
    pixels = NativeImageProcessor.applyChannelCurves(pixels, red, green, blue, width, height);
  }
  try {
    outputImage.setPixels(pixels, 0, width, 0, 0, width, height);
  } catch (IllegalStateException ise) {
  }
  return outputImage;
}

代码示例来源:origin: yipianfengye/android-zxingLibrary

public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;

    for (int y = 0; y < height; y++) {
      int outputOffset = y * width;
      for (int x = 0; x < width; x++) {
        int grey = yuv[inputOffset + x] & 0xff;
        pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
      }
      inputOffset += dataWidth;
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
  }
}

代码示例来源:origin: TommyLemon/Android-ZBLibrary

public Bitmap renderCroppedGreyscaleBitmap() {
  int width = getWidth();
  int height = getHeight();
  int[] pixels = new int[width * height];
  byte[] yuv = yuvData;
  int inputOffset = top * dataWidth + left;

  for (int y = 0; y < height; y++) {
   int outputOffset = y * width;
   for (int x = 0; x < width; x++) {
    int grey = yuv[inputOffset + x] & 0xff;
    pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
   }
   inputOffset += dataWidth;
  }

  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
  return bitmap;
 }
}

代码示例来源:origin: rmtheis/android-ocr

public Bitmap renderCroppedGreyscaleBitmap() {
 int width = getWidth();
 int height = getHeight();
 int[] pixels = new int[width * height];
 byte[] yuv = yuvData;
 int inputOffset = top * dataWidth + left;
 for (int y = 0; y < height; y++) {
  int outputOffset = y * width;
  for (int x = 0; x < width; x++) {
   int grey = yuv[inputOffset + x] & 0xff;
   pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
  }
  inputOffset += dataWidth;
 }
 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
 bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
 return bitmap;
}

代码示例来源:origin: journeyapps/zxing-android-embedded

public Bitmap createBitmap(BitMatrix matrix) {
  int width = matrix.getWidth();
  int height = matrix.getHeight();
  int[] pixels = new int[width * height];
  for (int y = 0; y < height; y++) {
    int offset = y * width;
    for (int x = 0; x < width; x++) {
      pixels[offset + x] = matrix.get(x, y) ? BLACK : WHITE;
    }
  }
  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
  return bitmap;
}

代码示例来源:origin: bumptech/glide

previousImage = getNextBitmap();
 previousImage.setPixels(dest, 0, downsampledWidth, 0, 0, downsampledWidth,
   downsampledHeight);
result.setPixels(dest, 0, downsampledWidth, 0, 0, downsampledWidth, downsampledHeight);
return result;

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

@Test
public void sameAs_bitmapsSamePixels() {
 int[] pixels = new int[] {0, 1, 2, 3};
 Bitmap original1 = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
 original1.setPixels(pixels, 0, 1, 0, 0, 2, 2);
 Bitmap original2 = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
 original2.setPixels(pixels, 0, 1, 0, 0, 2, 2);
 assertThat(original1.sameAs(original2)).isTrue();
}

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

@Test
public void sameAs_bitmapsDifferentPixels() {
 int[] pixels1 = new int[] {0, 1, 2, 3};
 Bitmap original1 = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
 original1.setPixels(pixels1, 0, 1, 0, 0, 2, 2);
 int[] pixels2 = new int[] {3, 2, 1, 0};
 Bitmap original2 = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
 original2.setPixels(pixels2, 0, 1, 0, 0, 2, 2);
 assertThat(original1.sameAs(original2)).isFalse();
}

代码示例来源:origin: TommyLemon/APIJSON

public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();  
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
    BitMatrix matrix = new MultiFormatWriter().encode(str,
        BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];
    
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        if (matrix.get(x, y)) {
          pixels[y * width + x] = BLACK;
        }
      }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
        Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
  }
}

代码示例来源:origin: yipianfengye/android-zxingLibrary

public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    BitMatrix matrix = new MultiFormatWriter().encode(str,
        BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];

    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        if (matrix.get(x, y)) {
          pixels[y * width + x] = BLACK;
        }
      }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
        Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

public static Bitmap generateQRCode(final String url) {
  Bitmap qrCode = null;
  Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
  hints.put(EncodeHintType.MARGIN, 2);
  try {
    BitMatrix matrix = new MultiFormatWriter()
        .encode(url, BarcodeFormat.QR_CODE, 200, 200, hints);
    int h = matrix.getHeight();
    int w = matrix.getWidth();
    int[] pixels = new int[h * w];
    for (int i = 0; i < h; i++) {
      int offset = i * w;
      for (int j = 0; j < w; j++) {
        pixels[offset + j] =
            matrix.get(j, i) ? Color.BLACK : Color.WHITE;
      }
    }
    qrCode = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    qrCode.setPixels(pixels, 0, w, 0, 0, w, h);
  } catch (WriterException ignored) {
    // ignored because exception would be thrown from ZXing library.
  }
  return qrCode;
}

代码示例来源:origin: TommyLemon/Android-ZBLibrary

public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();  
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
    BitMatrix matrix = new MultiFormatWriter().encode(str,
        BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];
    
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        if (matrix.get(x, y)) {
          pixels[y * width + x] = BLACK;
        }
      }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
        Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
  }
}

相关文章