use of com.hippo.io.UniFileInputStreamPipe in project EhViewer by seven332.
the class MainActivity method saveImageToTempFile.
private File saveImageToTempFile(UniFile file) {
if (null == file) {
return null;
}
Bitmap bitmap = null;
try {
bitmap = BitmapUtils.decodeStream(new UniFileInputStreamPipe(file), -1, -1, 500 * 500, false, false, null);
} catch (OutOfMemoryError e) {
// Ignore
}
if (null == bitmap) {
return null;
}
File temp = AppConfig.createTempFile();
if (null == temp) {
return null;
}
OutputStream os = null;
try {
os = new FileOutputStream(temp);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, os);
return temp;
} catch (IOException e) {
return null;
} finally {
IOUtils.closeQuietly(os);
}
}
use of com.hippo.io.UniFileInputStreamPipe in project EhViewer by seven332.
the class ImageSearchLayout method setImageUri.
public void setImageUri(@Nullable Uri imageUri) {
if (null == imageUri) {
return;
}
Context context = getContext();
UniFile file = UniFile.fromUri(context, imageUri);
if (null == file) {
return;
}
try {
int maxSize = context.getResources().getDimensionPixelOffset(R.dimen.image_search_max_size);
Bitmap bitmap = BitmapUtils.decodeStream(new UniFileInputStreamPipe(file), maxSize, maxSize);
if (null == bitmap) {
return;
}
File temp = AppConfig.createTempFile();
if (null == temp) {
return;
}
// TODO ehentai image search is bad when I'm writing this line.
// Re-compress image will make image search failed.
OutputStream os = null;
try {
os = new FileOutputStream(temp);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, os);
mImagePath = temp.getPath();
mPreview.setImageBitmap(bitmap);
mPreview.setVisibility(VISIBLE);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(os);
}
} catch (OutOfMemoryError e) {
Log.e(TAG, "Out of memory");
}
}
Aggregations