67 lines
2.2 KiB
Java
67 lines
2.2 KiB
Java
package com.kofax.mobile.sdk.ak;
|
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.nio.ByteBuffer;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class a {
|
|
private a() {
|
|
}
|
|
|
|
public static void b(ObjectOutputStream objectOutputStream, Bitmap bitmap) throws IOException {
|
|
objectOutputStream.writeObject(m(bitmap));
|
|
}
|
|
|
|
public static Bitmap d(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
|
return j((byte[]) objectInputStream.readObject());
|
|
}
|
|
|
|
public static byte[] m(Bitmap bitmap) throws IOException {
|
|
if (bitmap == null) {
|
|
return null;
|
|
}
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
if (!bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)) {
|
|
throw new IOException("Unable to compress bitmap");
|
|
}
|
|
return byteArrayOutputStream.toByteArray();
|
|
}
|
|
|
|
public static byte[] n(Bitmap bitmap) {
|
|
if (bitmap == null) {
|
|
return null;
|
|
}
|
|
ByteBuffer allocate = ByteBuffer.allocate(bitmap.getByteCount());
|
|
bitmap.copyPixelsToBuffer(allocate);
|
|
return allocate.array();
|
|
}
|
|
|
|
public static Bitmap a(byte[] bArr, int i, int i2, Bitmap.Config config) throws IOException {
|
|
if (bArr == null) {
|
|
return null;
|
|
}
|
|
Bitmap createBitmap = Bitmap.createBitmap(i, i2, config);
|
|
createBitmap.copyPixelsFromBuffer(ByteBuffer.wrap(bArr));
|
|
if (createBitmap == null || createBitmap.getByteCount() == 0) {
|
|
throw new IOException("Unable to decode bitmap");
|
|
}
|
|
return createBitmap;
|
|
}
|
|
|
|
public static Bitmap j(byte[] bArr) throws IOException {
|
|
if (bArr == null) {
|
|
return null;
|
|
}
|
|
Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length);
|
|
if (decodeByteArray != null) {
|
|
return decodeByteArray;
|
|
}
|
|
throw new IOException("Unable to decode bitmap");
|
|
}
|
|
}
|