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