|
|
@ -226,39 +226,73 @@ public class Camera1 extends CameraViewImpl { |
|
|
|
mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() { |
|
|
|
mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onPreviewFrame(byte[] data, Camera camera) { |
|
|
|
public void onPreviewFrame(byte[] data, Camera camera) { |
|
|
|
Camera.Parameters parameters = camera.getParameters(); |
|
|
|
new Thread(new ProcessStillTask(data, camera, mCameraInfo, new ProcessStillTask.OnStillProcessedListener() { |
|
|
|
int width = parameters.getPreviewSize().width; |
|
|
|
@Override |
|
|
|
int height = parameters.getPreviewSize().height; |
|
|
|
public void onStillProcessed(final byte[] data) { |
|
|
|
int rotation = mCameraInfo.orientation; |
|
|
|
getView().post(new Runnable() { |
|
|
|
byte[] rotatedData = YuvUtils.rotateNV21(data, width, height, rotation); |
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
int postWidth; |
|
|
|
getCameraListener().onPictureTaken(data); |
|
|
|
int postHeight; |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
switch (rotation) { |
|
|
|
} |
|
|
|
case 90: |
|
|
|
})).start(); |
|
|
|
case 270: |
|
|
|
} |
|
|
|
postWidth = height; |
|
|
|
}); |
|
|
|
postHeight = width; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
case 180: |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
postWidth = width; |
|
|
|
|
|
|
|
postHeight = height; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
YuvImage yuv = new YuvImage(rotatedData, parameters.getPreviewFormat(), postWidth, postHeight, null); |
|
|
|
static class ProcessStillTask implements Runnable { |
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
byte[] data; |
|
|
|
yuv.compressToJpeg(new Rect(0, 0, postWidth, postHeight), 50, out); |
|
|
|
Camera camera; |
|
|
|
|
|
|
|
Camera.CameraInfo cameraInfo; |
|
|
|
|
|
|
|
OnStillProcessedListener onStillProcessedListener; |
|
|
|
|
|
|
|
|
|
|
|
byte[] bytes = out.toByteArray(); |
|
|
|
public ProcessStillTask(byte[] data, Camera camera, Camera.CameraInfo cameraInfo, OnStillProcessedListener onStillProcessedListener) { |
|
|
|
getCameraListener().onPictureTaken(bytes); |
|
|
|
this.data = data; |
|
|
|
|
|
|
|
this.camera = camera; |
|
|
|
|
|
|
|
this.cameraInfo = cameraInfo; |
|
|
|
|
|
|
|
this.onStillProcessedListener = onStillProcessedListener; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
Camera.Parameters parameters = camera.getParameters(); |
|
|
|
|
|
|
|
int width = parameters.getPreviewSize().width; |
|
|
|
|
|
|
|
int height = parameters.getPreviewSize().height; |
|
|
|
|
|
|
|
int rotation = cameraInfo.orientation; |
|
|
|
|
|
|
|
byte[] rotatedData = YuvUtils.rotateNV21(data, width, height, rotation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int postWidth; |
|
|
|
|
|
|
|
int postHeight; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (rotation) { |
|
|
|
|
|
|
|
case 90: |
|
|
|
|
|
|
|
case 270: |
|
|
|
|
|
|
|
postWidth = height; |
|
|
|
|
|
|
|
postHeight = width; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
case 180: |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
postWidth = width; |
|
|
|
|
|
|
|
postHeight = height; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
YuvImage yuv = new YuvImage(rotatedData, parameters.getPreviewFormat(), postWidth, postHeight, null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
yuv.compressToJpeg(new Rect(0, 0, postWidth, postHeight), 50, out); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onStillProcessedListener.onStillProcessed(out.toByteArray()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface OnStillProcessedListener { |
|
|
|
|
|
|
|
void onStillProcessed(byte[] data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|