Bitmap处理的一些方法

    xiaoxiao2021-12-10  48

    public Bitmap clip() { Bitmap bitmap = Bitmap.createBitmap(rl_main.getWidth(), rl_main.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); rl_main.draw(canvas); bitmap=Bitmap.createBitmap(bitmap, 0,0, rl_main.getWidth(),rl_main.getHeight()); // bitmap=Bitmap.createBitmap(bitmap, 0,0, getWidth(),getHeight() - ly_share.getHeight()); return bitmap; // View rootView = this.getWindow().getDecorView(); // rootView.setDrawingCacheEnabled(true); // rootView.buildDrawingCache(); // Bitmap bitmap = rootView.getDrawingCache(); // // return bitmap; } private Bitmap Bytes2Bimap(byte[] data){ if (yuvType == null) { yuvType = new Type.Builder(rs, Element.U8(rs)).setX(data.length); in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT); rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(640).setY(480); out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT); } in.copyFrom(data); yuvToRgbIntrinsic.setInput(in); yuvToRgbIntrinsic.forEach(out); Bitmap bmpout = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888); out.copyTo(bmpout); return bmpout; } public LayerDrawable getLayerDrawable(Bitmap b1,Bitmap b2) { Drawable[] array = new Drawable[2]; array[0] = new BitmapDrawable(b1); array[1] = new BitmapDrawable(b2); LayerDrawable la = new LayerDrawable(array); // 其中第一个参数为层的索引号,后面的四个参数分别为lefttoprightbottom la.setLayerInset(0, 0, 0, 0, 0); la.setLayerInset(0, 0, 0, 0, 0); return la; } public static Bitmap rotatePicture(Bitmap bitmap, float degrees) { Matrix matrix = new Matrix(); matrix.reset(); matrix.setRotate(degrees); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // Matrix matrix1 = new Matrix(); // matrix1.reset(); // matrix.postScale(-1,1);//左右翻转 // bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), // bitmap.getHeight(), matrix1, true); return bitmap; } public static Bitmap resizeBitmap(Bitmap bitmap, int width, int height) { if (bitmap != null) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); if (w == width && h == height) { return bitmap; } if (w <= 0 || h <= 0) { return bitmap; } Double wrate = ((double) width) / w; Double hrate = ((double) height) / h; if (wrate == 0 || hrate == 0) { return bitmap; } Matrix matrix = new Matrix(); matrix.postScale(wrate.floatValue(), hrate.floatValue()); return Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); } return null; } public Bitmap getAddBitmap(Bitmap backBitmap,Bitmap frontBitmap) { // Bitmap newBitmap = null; // // newBitmap = Bitmap.createBitmap(b1); // Canvas canvas = new Canvas(newBitmap); // Paint paint = new Paint(); // paint.setAlpha(255); // // int w = b1.getWidth(); // int h = b1.getHeight(); // // int w_2 = b2.getWidth(); // int h_2 = b2.getHeight(); // // canvas.drawRect(0, 0, b1.getWidth(), b1.getHeight(), paint); // // paint = new Paint(); // paint.setAlpha(100); // Xfermode xFermode = new PorterDuffXfermode(PorterDuff.Mode.DST_OVER); // paint.setXfermode(xFermode); // canvas.drawBitmap(b2, Math.abs(w - w_2) / 2, // Math.abs(h - h_2) / 2, paint); // canvas.save(Canvas.ALL_SAVE_FLAG); // // 存储新合成的图片 // canvas.restore(); // return newBitmap; if (backBitmap == null || backBitmap.isRecycled() || frontBitmap == null || frontBitmap.isRecycled()) { Log.e(TAG, "backBitmap=" + backBitmap + ";frontBitmap=" + frontBitmap); return null; } Bitmap bitmap = backBitmap.copy(Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(bitmap); Rect baseRect = new Rect(0, 0, backBitmap.getWidth(), backBitmap.getHeight()); Rect frontRect = new Rect(0, 0, frontBitmap.getWidth(), frontBitmap.getHeight()); canvas.drawBitmap(frontBitmap, frontRect, baseRect, null); return bitmap; }
    转载请注明原文地址: https://ju.6miu.com/read-700135.html

    最新回复(0)