0

私はカスタムカメラを作りたいと思っています。写真を撮った後、私はカメラを設定しているのと同じアクティビティでイメージビューで設定します。私は写真を撮ることに成功しましたが、イメージビューでイメージを設定する前にイメージを縮小する必要がありました。実際のイメージをスケーリングする代わりに表示する方法はありますか? This is the real view of cameraイメージを拡大縮小してイメージビューで設定すると画質が低下して絞り込みます

写真を撮影した後、それは次のようになります:

The real camera image

私はコード最初のものは表面図であるカメラの本当の図であり、以下のよう

私のイメージがあります使用:

Camera.PictureCallback picture = new Camera.PictureCallback() { 
     @Override 
     public void onPictureTaken(byte[] data, Camera camera) { 
      mCamera.stopPreview(); 
      surface_view.setVisibility(View.INVISIBLE); 
      setupImageDisplay(data); 

     } 
    }; 

    private void setupImageDisplay(byte[] data) { 
     photo = BitmapFactory.decodeByteArray(data, 0, data.length); 
     photo = scaleDown(photo, true);//scaling down bitmap 
     imageview_photo.setImageBitmap(photo); //setting bitmap in imageview 

    } 

    public Bitmap scaleDown(Bitmap realImage, boolean filter) { 
     int screenWidth = width; 
     int screenHeight = height; 

     Bitmap scaled; 
     if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { 
      // Notice that width and height are reversed 
      scaled = Bitmap.createScaledBitmap(realImage, screenHeight, screenWidth, filter); 
      int w = scaled.getWidth(); 
      int h = scaled.getHeight(); 
      // Setting post rotate to 90 

      Matrix mtx = new Matrix(); 

      if (camera_id == Camera.CameraInfo.CAMERA_FACING_FRONT) { 
       float[] mirrorY = {-1, 0, 0, 0, 1, 0, 0, 0, 1}; 
       Matrix matrixMirrorY = new Matrix(); 
       matrixMirrorY.setValues(mirrorY); 

       mtx.postConcat(matrixMirrorY); 
      } 
      mtx.postRotate(90); 
      // Rotating Bitmap 
      realImage = Bitmap.createBitmap(scaled, 0, 0, w, h, mtx, filter); 
     } else {// LANDSCAPE MODE 
      //No need to reverse width and height 
      scaled = Bitmap.createScaledBitmap(realImage, screenHeight, screenWidth, filter); 
      int w = scaled.getWidth(); 
      int h = scaled.getHeight(); 
      // Setting post rotate to 90 

      Matrix mtx = new Matrix(); 

      if (camera_id == Camera.CameraInfo.CAMERA_FACING_FRONT) { 
       float[] mirrorY = {-1, 0, 0, 0, 1, 0, 0, 0, 1}; 
       Matrix matrixMirrorY = new Matrix(); 
       matrixMirrorY.setValues(mirrorY); 

       mtx.postConcat(matrixMirrorY); 
      } 
      mtx.postRotate(180); 
      // Rotating Bitmap 
      realImage = Bitmap.createBitmap(scaled, 0, 0, w, h, mtx, filter); 
     } 
     return realImage; 
    } 

画像を撮った後に、画像が縮小されたように見えますが、拡大後に画像が変わらない方法はありますか?

+0

はグライドライブラリを使用してみてください、それはあなたのイメージを自動縮尺されます。 –

+0

@ MaximeLiegeしかし、グライドではイメージのURLを教えてください。この場合、私は単純なビットマップを使用しています – SimpleMan

+0

いいえあなたもそれを与えることができますDrawablesも同様 –

答えて

0

一時ファイルであり、画像のサムネイルサイズを格納する別のファイルを作成することができます。このようにPOJOを作成して、両方の画像を保存することができます。小さなものを表示し、元のファイルを使用して高品質を保つことができます。

public class Image { 
File fullSize; 
File Thumbnail; 

public Image(File fullSize, File thumbnail) { 
    this.fullSize = fullSize; 
    Thumbnail = thumbnail; 
} 

public File getFullSize() { 
    return fullSize; 
} 

public void setFullSize(File fullSize) { 
    this.fullSize = fullSize; 
} 

public File getThumbnail() { 
    return Thumbnail; 
} 

public void setThumbnail(File thumbnail) { 
    Thumbnail = thumbnail; 
} 

}

+0

アプリケーション内に画像のファイルを保存する必要がありますか? – SimpleMan

+0

電話機のファイルストレージにアクセスする権限を使用します。そこにファイルを保存し、画像のパスも保存する必要があります。 –

+0

しかし、私は電話でその画像をどこにでも保存したくないのですか? – SimpleMan

関連する問題