My app, when user click capture button, start camera capture.
I use bitmap API. but sometimes memory problem.
so I want use Glide
library.
current my source
//Run on Preview call from Camera
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
YuvImage image = new YuvImage(data, previewFormat, 640, 480, null);
Rect rect = new Rect(0, 0, 640, 480);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
image.compressToJpeg(rect, 100, bao); //Compress data in YUY2 format into a rectangular area in jpeg format.
byte[] jpeg = bao.toByteArray();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap convertedImage = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length, options); //byte array to bitmap
mCallback.imageTaken(Bitmap.createScaledBitmap(convertedImage, 480, 360, true));
}
imageTaken(CaptureView.class)
//completed capture picture.
public void imageTaken(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
displayImage(bitmap); //preview bitmap image.
}
displayImage(CaptureView.class);
public class CaptureView extends View implements CaptureViewer {
private Bitmap mBitmap = null;
private Rect src = new Rect(120, 96, 342, 272);
private Rect dst;
private int viewWidth, viewHeight = 0;
@Override
protected void onMeasure(int width, int height) {
super.onMeasure(width, height);
viewWidth = getLayoutParams().width;
viewHeight = getLayoutParams().height;
dst = new Rect(0, 0, viewWidth, viewHeight);
}
@Override
public void displayImage(Bitmap image) {
if (mBitmap != null) {
mBitmap.recycle();
}
mBitmap = null;
mBitmap = Bitmap.createBitmap(image);
postInvalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(mBitmap, src, dst, null);
}
}
this source work, but I want use Glide library. most of the examples, use url glide library.
but I want bitmap to image glide library.
How to convert a bitmap or byte array to an image using glide android?