我有一个应用程序,可以从我的应用程序中拍照。
它在 Motorola RAZR HD Android 4.1.2 和 Galaxy S3 Android 4.1.1 上运行良好。
这两款手机之间的唯一区别是,当我使用摩托罗拉 RAZR 的应用程序拍照时,我可以预览图像,而当我使用三星 Galaxy S3 时,这不起作用。
我也想在三星中预览图像。我怎么能这样做?
此代码在我的主要活动中
setContentView(R.layout.principal_activity);
principalActivity_bt_TirarFoto = (Button) findViewById(R.id.principalActivity_bt_TirarFoto);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
cameraSurfaceView = new CameraSurfaceView(principalActivity_bt_TirarFoto.getContext());
cameraSurfaceView.setSoundEffectsEnabled(true);
cameraSurfaceView.setDrawingCacheEnabled(true);
preview = (FrameLayout) findViewById(R.id.principalActivity_fl_Camera);
preview.addView(cameraSurfaceView);
principalActivity_bt_TirarFoto.setSoundEffectsEnabled(true);
principalActivity_bt_TirarFoto.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
Log.i("PrincipalActivity","onClick - TirarFoto");
camera = cameraSurfaceView.getCamera();
camera.takePicture(new ShutterCallback() {
@Override
public void onShutter() {
AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mgr.playSoundEffect(AudioManager.FLAG_PLAY_SOUND);
}
}, null, hps = new HandlePictureStorage());
imageSelected = false;
mostrarBotoesConfirma();
}
});
这是我的 PictureCallback
public class HandlePictureStorage implements PictureCallback {
int wid = 0;
Bitmap newImage;
public HandlePictureStorage(){
}
@Override
public void onPictureTaken(byte[] picture, Camera camera) {
Matrix matrix = new Matrix();
Bitmap cameraBitmap = BitmapFactory.decodeByteArray(picture, 0, picture.length);
wid = 612;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(cameraBitmap, wid, wid, true);
Bitmap imagemRotacionada = Bitmap.createBitmap(scaledBitmap,0,0,scaledBitmap.getWidth(),scaledBitmap.getHeight(),matrix,true);
newImage = Bitmap.createBitmap (612, 612, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newImage);
canvas.drawBitmap(imagemRotacionada, 0f, 0f, null);
cameraBitmap.recycle();
cameraBitmap = null;
}
public Bitmap getBitmap(){
return newImage;
}
}
谢谢!
== 编辑 1 ==
这是 logcat @Segi。我运行我的应用程序并拍照,这是他提供的日志。
06-10 08:53:50.965: I/PrincipalActivity(14549): onCreate
06-10 08:53:50.985: D/dalvikvm(14549): GC_FOR_ALLOC freed 3074K, 19% free 17673K/21575K, paused 9ms, total 9ms
06-10 08:53:51.015: D/dalvikvm(14549): GC_FOR_ALLOC freed <1K, 12% free 19135K/21575K, paused 8ms, total 8ms
06-10 08:53:51.020: I/dalvikvm-heap(14549): Grow heap (frag case) to 21.763MB for 2663440-byte allocation
06-10 08:53:51.040: D/dalvikvm(14549): GC_CONCURRENT freed 0K, 11% free 21737K/24199K, paused 11ms+2ms, total 21ms
06-10 08:53:51.040: D/dalvikvm(14549): WAIT_FOR_CONCURRENT_GC blocked 2ms
06-10 08:53:51.095: D/dalvikvm(14549): GC_CONCURRENT freed 2160K, 12% free 21580K/24327K, paused 1ms+2ms, total 10ms
06-10 08:53:51.095: D/dalvikvm(14549): WAIT_FOR_CONCURRENT_GC blocked 7ms
06-10 08:53:51.115: I/Teste(14549): last picture (20130610_025810) taken on: 2013-06-10
06-10 08:53:51.115: I/System.out(14549): Not a DRM File, opening notmally
06-10 08:53:51.120: I/System.out(14549): buffer returned
06-10 08:53:51.130: D/dalvikvm(14549): GC_FOR_ALLOC freed 230K, 10% free 21968K/24327K, paused 8ms, total 9ms
06-10 08:53:51.160: I/dalvikvm-heap(14549): Grow heap (frag case) to 52.470MB for 31961104-byte allocation
06-10 08:53:51.180: D/dalvikvm(14549): GC_CONCURRENT freed <1K, 5% free 53180K/55559K, paused 11ms+2ms, total 21ms
06-10 08:53:51.180: D/dalvikvm(14549): WAIT_FOR_CONCURRENT_GC blocked 10ms
06-10 08:53:51.180: W/CursorWrapperInner(14549): Cursor finalized without prior close()
06-10 08:53:51.180: D/dalvikvm(14549): WAIT_FOR_CONCURRENT_GC blocked 10ms
06-10 08:53:51.535: I/Entrou no Resume(14549): Entrou no Resume
06-10 08:53:51.590: I/CameraSurfaceView(14549): Surface Created
06-10 08:53:51.910: I/Camera Width: 320(14549): Camera Height: 240
06-10 08:53:51.940: I/CameraSurfaceView(14549): Surface Changed
06-10 08:53:52.415: E/SpannableStringBuilder(14549): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-10 08:53:52.415: E/SpannableStringBuilder(14549): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-10 08:54:01.935: I/PrincipalActivity(14549): onClick - TirarFoto
06-10 08:54:02.150: D/dalvikvm(14549): GC_FOR_ALLOC freed 110K, 5% free 53261K/55559K, paused 12ms, total 12ms
06-10 08:54:02.155: I/dalvikvm-heap(14549): Grow heap (frag case) to 55.186MB for 2764816-byte allocation
06-10 08:54:02.185: D/dalvikvm(14549): GC_CONCURRENT freed 5067K, 13% free 50893K/58311K, paused 12ms+2ms, total 29ms
06-10 08:54:02.215: D/dalvikvm(14549): GC_FOR_ALLOC freed <1K, 11% free 52357K/58311K, paused 13ms, total 13ms
06-10 08:54:02.230: D/dalvikvm(14549): GC_FOR_ALLOC freed <1K, 8% free 53820K/58311K, paused 13ms, total 13ms
再次感谢!!!