151 lines
5.5 KiB
Java
151 lines
5.5 KiB
Java
package com.ubt.jimu.utils;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.renderscript.Allocation;
|
|
import android.renderscript.Element;
|
|
import android.renderscript.RenderScript;
|
|
import android.renderscript.ScriptIntrinsicBlur;
|
|
import android.util.DisplayMetrics;
|
|
import android.view.View;
|
|
import androidx.core.content.ContextCompat;
|
|
import com.ubt.jimu.utils.ExternalOverFroyoUtils;
|
|
import com.ubtech.utils.BitmapFile;
|
|
import com.ubtech.utils.BlurHelper;
|
|
import com.ubtech.utils.DensityUtils;
|
|
import java.io.File;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class BitmapUtils {
|
|
public static Bitmap a(Context context, Bitmap bitmap, String str) {
|
|
File file = new File(ExternalOverFroyoUtils.a(context, ExternalOverFroyoUtils.Dir.Image.getName()), str);
|
|
if (file.exists()) {
|
|
try {
|
|
int[] a = DensityUtils.a(context);
|
|
return a(file.getPath(), Math.max(a[0], a[1]), Math.min(a[0], a[1]));
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
try {
|
|
BlurHelper a2 = BlurHelper.a(context);
|
|
a2.a(bitmap);
|
|
a2.a(25);
|
|
a2.a(1.0f);
|
|
Bitmap a3 = a2.a();
|
|
if (a3 == null) {
|
|
return null;
|
|
}
|
|
BitmapFile.a(a3, file.getAbsolutePath());
|
|
return a3;
|
|
} catch (Exception e2) {
|
|
e2.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static Bitmap a(Context context, Bitmap bitmap, float f) {
|
|
if (bitmap == null) {
|
|
return null;
|
|
}
|
|
Bitmap createBitmap = Bitmap.createBitmap(bitmap);
|
|
RenderScript create = RenderScript.create(context);
|
|
ScriptIntrinsicBlur create2 = ScriptIntrinsicBlur.create(create, Element.U8_4(create));
|
|
Allocation createFromBitmap = Allocation.createFromBitmap(create, bitmap);
|
|
Allocation createFromBitmap2 = Allocation.createFromBitmap(create, createBitmap);
|
|
create2.setRadius(f);
|
|
create2.setInput(createFromBitmap);
|
|
create2.forEach(createFromBitmap2);
|
|
createFromBitmap2.copyTo(createBitmap);
|
|
create2.destroy();
|
|
createFromBitmap2.destroy();
|
|
createFromBitmap.destroy();
|
|
create.destroy();
|
|
return createBitmap;
|
|
}
|
|
|
|
public static int a(BitmapFactory.Options options, int i, int i2) {
|
|
int i3 = options.outHeight;
|
|
int i4 = options.outWidth;
|
|
int i5 = 1;
|
|
if (i3 > i2 || i4 > i) {
|
|
int i6 = i3 / 2;
|
|
int i7 = i4 / 2;
|
|
while (true) {
|
|
if (i6 / i5 <= i2 && i7 / i5 <= i7) {
|
|
break;
|
|
}
|
|
i5 *= 2;
|
|
}
|
|
}
|
|
return i5;
|
|
}
|
|
|
|
public static Bitmap a(String str, int i, int i2) {
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
options.inJustDecodeBounds = true;
|
|
BitmapFactory.decodeFile(str, options);
|
|
options.inSampleSize = a(options, i, i2);
|
|
options.inJustDecodeBounds = false;
|
|
return BitmapFactory.decodeFile(str, options);
|
|
}
|
|
|
|
public static Bitmap a(Context context, View view) {
|
|
Bitmap bitmap = null;
|
|
if (context == null) {
|
|
return null;
|
|
}
|
|
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
|
int i = displayMetrics.heightPixels;
|
|
int i2 = displayMetrics.widthPixels;
|
|
if (view != null) {
|
|
view.clearFocus();
|
|
view.setPressed(false);
|
|
boolean willNotCacheDrawing = view.willNotCacheDrawing();
|
|
view.setWillNotCacheDrawing(false);
|
|
int drawingCacheBackgroundColor = view.getDrawingCacheBackgroundColor();
|
|
view.setDrawingCacheBackgroundColor(0);
|
|
float alpha = view.getAlpha();
|
|
view.setAlpha(1.0f);
|
|
if (drawingCacheBackgroundColor != 0) {
|
|
view.destroyDrawingCache();
|
|
}
|
|
view.measure(View.MeasureSpec.makeMeasureSpec(i2, 1073741824), View.MeasureSpec.makeMeasureSpec(i, 1073741824));
|
|
view.layout(0, 0, i2, i);
|
|
view.bringToFront();
|
|
view.buildDrawingCache();
|
|
Bitmap drawingCache = view.getDrawingCache();
|
|
if (drawingCache == null) {
|
|
return null;
|
|
}
|
|
bitmap = Bitmap.createBitmap(drawingCache);
|
|
view.setAlpha(alpha);
|
|
view.destroyDrawingCache();
|
|
view.setWillNotCacheDrawing(willNotCacheDrawing);
|
|
view.setDrawingCacheBackgroundColor(drawingCacheBackgroundColor);
|
|
}
|
|
return a(context, bitmap, 25.0f);
|
|
}
|
|
|
|
public static Bitmap a(Drawable drawable) {
|
|
Bitmap createBitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
|
Canvas canvas = new Canvas(createBitmap);
|
|
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
|
drawable.draw(canvas);
|
|
return createBitmap;
|
|
}
|
|
|
|
public static Bitmap a(Context context, int i, int i2, int i3) {
|
|
Drawable c = ContextCompat.c(context, i);
|
|
Bitmap createBitmap = Bitmap.createBitmap(i2, i3, Bitmap.Config.ARGB_8888);
|
|
Canvas canvas = new Canvas(createBitmap);
|
|
c.setBounds(0, 0, i2, i3);
|
|
c.draw(canvas);
|
|
return createBitmap;
|
|
}
|
|
}
|