Refine search
- Common ways to obtain Bitmap
private void myMethod () {}
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 BitmapLuminanceSource(Bitmap bitmap) { super(bitmap.getWidth(), bitmap.getHeight()); // 首先,要取得该图片的像素数组内容 int[] data = new int[bitmap.getWidth() * bitmap.getHeight()]; this.bitmapPixels = new byte[bitmap.getWidth() * bitmap.getHeight()]; bitmap.getPixels(data, 0, getWidth(), 0, 0, getWidth(), getHeight()); // 将int数组转换为byte数组,也就是取像素值中蓝色值部分作为辨析内容 for (int i = 0; i < data.length; i++) { this.bitmapPixels[i] = (byte) data[i]; } }
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 static Bitmap getGradientBitmap(int width, int height, @ColorInt int color) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int alpha = Color.alpha(color); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); for (int y = 0; y < height; y++) { int gradientAlpha = (int) ((float) alpha * (float) (height - y) * (float) (height - y) / (float) height / (float) height); for (int x = 0; x < width; x++) { pixels[x + y * width] = Color.argb(gradientAlpha, red, green, blue); } } bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); 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; }
private static void blurSoftware(Bitmap bitmap, float radius) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); int[] halfResult = new int[width * height]; int rad = (int) Math.ceil(radius);