Closed SteveYurka closed 9 years ago
Many Thanks. Simply save data[] to bitmap in onPreviewFrame method. On click of button make a boolean true and in onPreviewFrame method make that boolean false.
If this doesn't help you, let me know I will give you working code on next working day i.e. Monday.
If that's possible to provide code that would be amazing and appreciated, I'm curious if you have actually added anything else to this library in the past year and just not pushed it to github?
And also why have you have build it.. fun, work, your own app? If you don't mind
@Override public void onClick(View v) { if(v.getId() == R.id.btn_capture_pitcure) { isTakePic = true; } }
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (isTakePic) {
isTakePic = false;
Camera.Parameters parameters = cameraParameters;
int imageFormat = parameters.getPreviewFormat();
Bitmap bitmap = null;
byte[] byt = null;
if (imageFormat == ImageFormat.NV21) {
YuvImage yuvImage = new YuvImage(data, imageFormat,previewWidth, previewHeight, null);
Rect rect = new Rect(0, 0, previewWidth, previewHeight);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
yuvImage.compressToJpeg(rect, 100, outputStream);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
bitmap = BitmapFactory.decodeByteArray(outputStream.toByteArray(), 0, outputStream.size(),options);
byt = outputStream.toByteArray();
} else if (imageFormat == ImageFormat.JPEG
|| imageFormat == ImageFormat.RGB_565) {
Options opts = new Options();
opts.inJustDecodeBounds = true;
int sampleSize = 1;
opts.inSampleSize = sampleSize;
bitmap = BitmapFactory.decodeByteArray(data, 0,
data.length, opts);
}
if (bitmap != null) {
Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
if (bitmap != null && imageFormat != ImageFormat.NV21) {
int w = mutableBitmap.getWidth();
int h = mutableBitmap.getHeight();
Matrix mtx = new Matrix();
mtx.setRotate(90);
someCanvasView.setMainBitmap(Bitmap.createBitmap(mutableBitmap, 0, 0, w, h, mtx, true));
} else if (imageFormat == ImageFormat.NV21
&& (bitmap != null)) {
if(cameraSelection == CameraInfo.CAMERA_FACING_FRONT)
{
Matrix rotateRight = new Matrix();
rotateRight.preRotate(90);
float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1};
rotateRight = new Matrix();
Matrix matrixMirrorY = new Matrix();
matrixMirrorY.setValues(mirrorY);
rotateRight.postConcat(matrixMirrorY);
rotateRight.preRotate(270);
final Bitmap rImg= Bitmap.createBitmap(mutableBitmap, 0, 0,
mutableBitmap.getWidth(), mutableBitmap.getHeight(), rotateRight, true);
someCanvasView.setMainBitmap(rImg);
}
else
{
someCanvasView.setMainBitmap(mutableBitmap);
}
}
bitmap.recycle();
bitmap = null;
}
}
}
I started working with the intentions of R&D only and when I succeeded , we have used in few office apps (work) too. This code just provide a way to record audio and video separately and then merge them both using ffmpeg command, so that we can have pause/record function for user. This purpose was accomplished a year ago, so never updated the code. But you can add as many image effects/video enhancement stuff as per your requirement. At the end every thing is bytes !!!
Really cool man, thanks for the update, you seem like a very talented android engineer, do you mind sending me an email at stephen.yurka@gmail.com or adding me on Linkedin at https://www.linkedin.com/in/stephenyurka , I wouldn't mind asking you a couple of questions.
Thanks for your time
Yeah Sure .
Welcome !
By the way this project is absolutely amazing, i'm surprised it isn't really popular after the massive bunch of bad camera projects i've tested, not an issue I was just wondering how you would suggest I go about capturing a single frame (to take a picture instead of a video)?