我的Android应用程序预览图片

我的Android应用程序预览图片,android,android-camera,image,preview,Android,Android Camera,Image,Preview,我有一个应用程序,可以从我的应用程序中拍照 它在摩托罗拉RAZR高清安卓4.1.2和Galaxy S3安卓4.1.1上运行良好 这两款手机之间的唯一区别是,当我使用摩托罗拉RAZR的应用程序拍照时,我可以预览图像,而当我使用三星Galaxy S3时,这不起作用 我也想预览三星的图像。我怎么能做到 这是我的主要活动 setContentView(R.layout.principal_activity); principalActivity_bt_TirarFoto = (Button) findV

我有一个应用程序,可以从我的应用程序中拍照

它在摩托罗拉RAZR高清安卓4.1.2和Galaxy S3安卓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();

        }
    });
这是我的照片背景

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
06-10 08:53:50.965:I/PrincipalActivity(14549):onCreate
06-10 08:53:50.985:D/dalvikvm(14549):释放3074K的所有物质的GC_,19%的自由17673K/21575K,暂停9ms,总计9ms
06-10 08:53:51.015:D/dalvikvm(14549):所有释放的GC\uOk

我找到了解决办法

就像@Segi之前说的。S3有一个bug,为了避免这个问题,我做了

首先我得到了手机的型号

String phoneModel = android.os.Build.MODEL;
然后我在拍摄模型时进行验证。如果是Galaxy S3,我会使用cameraSurfaceView的方法作为背景。这是代码

if (phoneModel.equals("GT-I9305T")){
   camera.takePicture(new ShutterCallback() {

   @Override
   public void onShutter() {
       AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
       mgr.playSoundEffect(AudioManager.FLAG_PLAY_SOUND);
   }
}, null, new Camera.PictureCallback(){

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {

    int wid = 0;

    Matrix matrix = new Matrix();
    matrix.setRotate(90);

    Bitmap cameraBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

    wid = 612;

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(cameraBitmap, wid, wid, true);
    Bitmap imagemRotacionada = Bitmap.createBitmap(scaledBitmap,0,0,scaledBitmap.getWidth(),scaledBitmap.getHeight(),matrix,true);

    imagemS3 = Bitmap.createBitmap (612, 612, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(imagemS3);
    canvas.drawBitmap(imagemRotacionada, 0f, 0f, null);

    cameraBitmap.recycle();
    cameraBitmap = null;

    scaledBitmap.recycle();

    imagemRotacionada.recycle();

    Drawable imageDrawable = new BitmapDrawable(getResources(),imagemS3);
    cameraSurfaceView.setBackground(imageDrawable);

}});
或者你可以看看我在哪里找到了解决方案


谢谢

把你的日志放在这里。。我认为错误即将从内存中消失..您的日志中没有提到错误。。!!我知道。真奇怪。我在摩托罗拉RAZR中使用我的应用程序,效果很好,我在三星S3中使用,我看不到我在接受或不接受之前拍摄的照片,我没有任何错误。我真的不知道该怎么做才能解决这个问题。。这意味着你应该压缩你的图像。因为这是S3中出现的主要问题。所以对于S3,我不能压缩图像?