2017-12-31 93 views
1

https://www.youtube.com/watch?v=GaizJhx-FVgのチュートリアルに従ってカメラ機能を有効にしましたが、画像をキャプチャした後、その品質は非常に低くなります。イメージの品質をどのように調整することができるかについての考えはありますか? Xamarinのカメラを使って撮影後の画像の品質を向上させる方法Xamarinカメラを使用してキャプチャ後の画質を向上させる方法は?

using Android.App; 
using Android.Widget; 
using Android.OS; 
using System; 
using Android.Content; 
using Android.Runtime; 
using Android.Views; 
using Android.Graphics; 

namespace Interactive_Ringgit_Recognizer_Try 
{ 
    [Activity(Label = "Interactive_Ringgit_Recognizer", MainLauncher = true)] 
    public class MainActivity : Activity 
    { 
     ImageView imageView; 

     protected override void OnCreate(Bundle savedInstanceState) 
     { 
      base.OnCreate(savedInstanceState); 

      // Set our view from the "main" layout resource 
      SetContentView(Resource.Layout.Main); 

      var btnCamera = FindViewById<Button>(Resource.Id.btnCamera); 
      imageView = FindViewById<ImageView>(Resource.Id.imageView); 

      btnCamera.Click += BtnCamera_Click; 
     } 

     protected override void OnActivityResult(int requestCode,[GeneratedEnum] Result resultCode, Intent data) 
     { 
      base.OnActivityResult(requestCode, resultCode, data); 
      Bitmap bitmap = (Bitmap)data.Extras.Get("data"); 
      imageView.SetImageBitmap(bitmap); 
     } 

     private void BtnCamera_Click(object sender, EventArgs e) 
     { 
      Intent intent = new Intent   (Android.Provider.MediaStore.ActionImageCapture); 
      StartActivityForResult(intent, 0); 
     } 
    } 
} 

答えて

1

これは、カメラ機能のコードですか?

カメラから写真を撮るときは、写真を保存するディレクトリを作成し、ファイルを作成してUriをインテントに追加すると、カメラアプリケーションによって結果ファイルがこのファイルに保存されます。

public static class App { 
    public static Java.IO.File _file; 
    public static Java.IO.File _dir;  
    public static Bitmap bitmap; 
} 

private void TakeAPicture(object sender, EventArgs eventArgs) 
{ 
    Intent intent = new Intent(MediaStore.ActionImageCapture); 
    App._file = new File(App._dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid())); 
    intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(App._file)); 
    StartActivityForResult(intent, 0); 
} 

OnActivityResultの方法では、写真をデバイスイメージギャラリーで使用できるようにします。次に、表示する画像のサイズを変更するヘルパーメソッドを呼び出すことができます。

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) 
{ 
    base.OnActivityResult(requestCode, resultCode, data); 

    // Make it available in the gallery 
    Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); 
    Uri contentUri = Uri.FromFile(App._file); 
    mediaScanIntent.SetData(contentUri); 
    SendBroadcast(mediaScanIntent); 

    // Display in ImageView. We will resize the bitmap to fit the display 
    // Loading the full sized image will consume to much memory 
    // and cause the application to crash. 

    int height = Resources.DisplayMetrics.HeightPixels; 
    int width = _imageView.Height; 
    App.bitmap = App._file.Path.LoadAndResizeBitmap(width, height); 
    if (App.bitmap != null) 
    { 
     _imageView.SetImageBitmap(App.bitmap); 
     App.bitmap = null; 
    } 

    // Dispose of the Java side bitmap. 
    GC.Collect(); 
} 

LoadAndResizeBitmap方法:完全なコードについては

public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height) 
{ 
    // First we get the dimensions of the file on disk 
    BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true }; 
    BitmapFactory.DecodeFile(fileName, options); 

    // Next we calculate the ratio that we need to resize the image by 
    // in order to fit the requested dimensions. 
    int outHeight = options.OutHeight; 
    int outWidth = options.OutWidth; 
    int inSampleSize = 1; 

    if (outHeight > height || outWidth > width) 
    { 
     inSampleSize = outWidth > outHeight 
          ? outHeight/height 
          : outWidth/width; 
    } 

    // Now we will load the image and have BitmapFactory resize it for us. 
    options.InSampleSize = inSampleSize; 
    options.InJustDecodeBounds = false; 
    Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options); 

    return resizedBitmap; 
} 

、あなたがこのofficial documentを参照することができます。

+0

こんにちは、写真はギャラリーにはありません 、ギャラリーはどこですか? –

+0

「ギャラリーで使えない」とはどういう意味ですか?もう少し詳しく教えていただけますか? –

+0

申し訳ありませんタイプミス、ギャラリーに保存できません –

関連する問題