【发布时间】:2015-07-02 15:42:18
【问题描述】:
目前我正在使用自定义相机应用程序,预览看起来还不错。但是当我拍照并保存设备时,图片减少了 80%(也是大小)。有人知道为什么会这样吗?画廊的质量也很差。我正在使用这个相机插件
这就是参数。我无法添加所有代码(getPicture 和 Save codes)。你可以从我分享的链接中看到。
CameraPrewiev...
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (getHolder().getSurface() == null) {
return;
}
try {
camera.stopPreview();
} catch (Exception e){
// tried to stop a non-existent preview
}
try {
Camera.Parameters cameraParameters = camera.getParameters();
Size previewSize = optimimalPreviewSize(width, height);
cameraParameters.setPreviewSize(previewSize.width, previewSize.height);
camera.setParameters(cameraParameters);
camera.setPreviewDisplay(holder);
camera.setDisplayOrientation(90);
camera.startPreview();
} catch (Exception e){
Log.d(TAG, "Error starting camera preview: " + e.getMessage());
}
}
private Size optimimalPreviewSize(int targetWidth, int targetHeight) {
List<Size> sizes = camera.getParameters().getSupportedPreviewSizes();
float targetAspectRatio = (float) targetWidth / targetHeight;
List<Size> sizesWithMatchingAspectRatios = filterByAspectRatio(targetAspectRatio, sizes);
if (sizesWithMatchingAspectRatios.size() > 0) {
return optimalSizeForHeight(sizesWithMatchingAspectRatios, targetHeight);
}
return optimalSizeForHeight(sizes, targetHeight);
}
private List<Size> filterByAspectRatio(float targetAspectRatio, List<Size> sizes) {
List<Size> filteredSizes = new ArrayList<Size>();
for (Size size : sizes) {
// reverse the ratio calculation as we've flipped the orientation
float aspectRatio = (float)size.height / size.width;
if (aspectRatio == targetAspectRatio) {
filteredSizes.add(size);
}
}
return filteredSizes;
}
private Size optimalSizeForHeight(List<Size> sizes, int targetHeight) {
Size optimalSize = null;
float minimumHeightDelta = Float.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minimumHeightDelta) {
optimalSize = size;
minimumHeightDelta = Math.abs(size.height - targetHeight);
}
}
return optimalSize;
}
【问题讨论】:
-
1.你提供了一个 ios 库的链接 2. 也许在 github 上打开一张票?
-
抱歉,我立即更正了。