アプリから写真を撮るアプリケーションがあります。
Motorola RAZR HD Android 4.1.2 および Galaxy S3 Android 4.1.1 で問題なく動作しています。
2 つの電話の唯一の違いは、Motorola RAZR でアプリを使用して写真を撮ると画像をプレビューでき、Samsung 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
再度、感謝します!!!