2017-12-31 92 views
1

https://www.youtube.com/watch?v=GaizJhx-FVg에 대한 자습서를 따라 카메라 기능을 활성화했지만 이미지를 캡처하면 품질이 매우 낮아집니다. 이미지의 품질을 조정하는 방법에 대한 아이디어가 있습니까?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

어떻게 자 마린 카메라를 사용하여 촬영 후 이미지의 품질을 높이기 위해?

당신이 카메라에서 사진을 촬영, 당신이 파일을 생성하고 의도는 열린 우리당을 추가하여,에서 사진을 저장할 디렉토리를 생성 할 수 있습니다, 카메라 응용 프로그램이 파일의 결과 사진을 저장합니다.

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

미안하지만 이미지가 갤러리에 저장되지 않습니다 –