これまでのところ、私のソリューションは、ビューがサーフェスビューと同じビューを占めるレイアウトを作成することです。
その後、私はその後、私がするコールバックを設定し
//Get our screen size
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
DisplayMetrics metrics = getResources().getDisplayMetrics();
Point size = new Point();
try {
display.getSize(size);
w_width = size.x;
w_height = size.y;
} catch (NoSuchMethodError e) {
w_width = display.getWidth();
w_height = display.getHeight();
}
(私の場合には、それは画面の大きさです)、プレビュー用のビューの境界を取得します:したがって、基本的
callback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] bytes, Camera camera) {
//Get the view bounds to determine how to manipulate this image
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
//If the image is smaller than the screen, don't make the image bigger
int finalWidth = (w_width < options.outWidth) ? w_width : options.outWidth;
int finalHeight = (w_height < options.outHeight) ? w_height : options.outHeight;
int inSampleSize = 1;
options = new BitmapFactory.Options();
if (finalHeight > w_height || finalWidth > w_width) {
// Calculate ratios of height and width to requested height and width
final int heightRatio = Math.round((float) finalHeight/(float) w_height);
final int widthRatio = Math.round((float) finalWidth/(float) w_width);
// Choose the smallest ratio as inSampleSize value, this will guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
options.inSampleSize = inSampleSize;
//Decode the smaller image
Bitmap b = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
//Rotate the image correctly
Matrix mat = new Matrix();
mat.postRotate(orientation);
Bitmap newBitmap = Bitmap.createBitmap(b, 0, 0, options.outWidth, options.outHeight, mat, true);
imagePreview.setBackgroundDrawable(new BitmapDrawable(newBitmap));
imagePreview.setVisibility(View.VISIBLE);
}
};
表面ビューはプレビューの表示を停止することはありませんが、イメージビューはそれを隠してユーザーが見ることはできません。
次に、ユーザーが画像を保持しないと決めた場合、ビューを再表示するだけで、surfaceViewはライブプレビューを表示し続けます。幸いなことに、GS3は "camera.startPreview();"プレビューが既に行われている場合でも可能です。
私は本当にこの答えが嫌いですが、それは銀河のS3で動作する瞬間に私が持っているすべてです。それは私が試した古いデバイス(2.3以上)で動作しましたが、それは間違いなく単なる回避策です。
私はこの問題も抱えています。あなたは解決策を見つけましたか? – BoredAndroidDeveloper
まだありません。 :( – GeX
誰かがコード例が必要な場合、このアプリケーションでこの問題が発生します:https://github.com/dawidgatti/dgCam – BoredAndroidDeveloper