2017-01-12 15 views
0

私はAndroidには新しく、オーバーレイ画像付きのカスタムカメラを使用して画像をキャプチャする必要があるプロジェクトに取り組んでいます。オーバーレイ画像の向きが保存後に変更される

私はオーバーレイ(合成画像)で画像をキャプチャできますが、新しい組み合わせ画像を保存した後にオーバーレイ画像の向きが変わるという問題があります。つまり、オーバーレイ画像は主にポートレートモードで設定されますが、モード。

私は描画イメージの向きを変更する方法ために多くのことを検索しましたが、姿勢の変化は、私は、ビットマップおよび変更の回転に描画イメージを変更するビットマップimage.If用でどこでも、それはどのオーバーレイimage.iは」didnの表示されません。コードの何が間違っているかを知っている。 私のコードは以下の通りです。ここで

public void onPictureTaken(byte[] arg0, Camera camera) { 
Bitmap cameraBitmap = BitmapFactory.decodeByteArray(arg0, 0, arg0.length); 
     int wid = cameraBitmap.getWidth(); 
     int hgt = cameraBitmap.getHeight(); 
     Bitmap newImage = Bitmap.createBitmap(wid,hgt,Bitmap.Config.ARGB_8888); 
     Canvas canvas = new Canvas(newImage); 
     canvas.drawBitmap(cameraBitmap, 0f, 0f, null); 
     // Drawable drawable = getResources().getDrawable(R.drawable.frame); 
     // drawable.setBounds(0,0,drawable.getIntrinsicWidth()*1/2, drawable.getIntrinsicHeight()*1/2); 
     Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.frame); 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(270); 
     Bitmap scaledBitmap = Bitmap.createScaledBitmap(b, 100, 200, true); 
     Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true); 
     Drawable drawable = new BitmapDrawable(getResources(), rotatedBitmap); 
     drawable.draw(canvas); 
     File storagePath = new File(Environment.getExternalStorageDirectory() + "/Photo/"); 
     storagePath.mkdirs(); 
     File myImage = new File(storagePath,Long.toString(System.currentTimeMillis()) + ".jpg"); 
     try 
     { 
      FileOutputStream out = new FileOutputStream(myImage); 
      ExifInterface exif = new ExifInterface(cameraBitmap.toString()); 
      Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); 
      if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")) { 
       newImage = rotate(newImage, 90); 
      } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")) { 
       newImage = rotate(newImage, 270); 
      } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")) { 
       newImage = rotate(newImage, 180); 
      } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")) { 
       newImage = rotate(newImage, 90);} 
      newImage.compress(Bitmap.CompressFormat.JPEG, 90, out); 
      camera.startPreview(); 
      Intent intent = new Intent(); 
      intent.setAction(Intent.ACTION_VIEW); 
      intent.setDataAndType(Uri.parse("file://" + myImage.getAbsolutePath()), "image/*"); 
      startActivity(intent); 
      newImage.recycle(); 
      newImage = null; 
      out.flush(); 
      out.close(); 
     } 
     catch(FileNotFoundException e) 
     { 
      Log.d("In Saving File", e + ""); 
     } 
     catch(IOException e) 
     { 
      Log.d("In Saving File", e + ""); 
     } 
    }}; 

     public Bitmap rotate(Bitmap bitmap, int degree) { 
    int w = bitmap.getWidth(); 
    int h = bitmap.getHeight(); 
    Matrix mtx = new Matrix(); 
    //  mtx.postRotate(degree); 
    mtx.setRotate(degree); 
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); 
}` 

レイアウトは、カメラImageViewのオーバーレイ画像のためmainactivityに呼び出しされています。助けを事前に

surfaceView = (SurfaceView) findViewById(R.id.cameraView);//for camera view surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext());//for overlay view inflated over the surfaceView View view = controlInflater.inflate(R.layout.overlay, null); view.setSaveEnabled(true); LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); this.addContentView(view, layoutParamsControl); 感謝。

答えて

0

このトピックに関するいくつかの調査の後、私は回転可能(アニメーションなし)または描画可能なイメージのイメージの向きを変更することはできません。 私は文書Bitmap & Viewを調べます。 setDrawingCacheEnabledのボイド(ブール有効) が描画キャッシュを有効または無効にし

: ビューのドキュメントがあると述べています。描画キャッシュを有効にすると、次にgetDrawingCache()またはbuildDrawingCache()を呼び出すと、ビューがビットマップに描画されます。 draw(android.graphics.Canvas)を呼び出すと、キャッシュが有効になっているときにキャッシュから描画されません。その後

iがonPictureTaken()メソッドでsetDrawaingCacheEnabled ()を使用して、オリジナルと同じ向きで描画可能からの画像にアクセスするために次の行を追加します。これに加えて

view.setDrawingCacheEnabled(true); 
     Bitmap viewCapture = Bitmap.createBitmap(view.getDrawingCache()); 
     view.setDrawingCacheEnabled(false); 

出力画面に描画イメージの大きさを設定するためには、(私は私の質問では無視)は、setBounds方法

drawable.setBounds(0, 0, drawable.getIntrinsicWidth() * 1/2, drawable.getIntrinsicHeight() * 1/2);

を使用することが必要です
関連する問題