2016-06-28 7 views
0

cameracaptureuiを使用して画像をキャプチャしましたが、画像コントロールに画像があります。 問題は、このキャプチャしたイメージをデータベースに保存する方法です。 通常、このタスクはWindowsフォームで画像をByetsに変換することで行いました。今はUWPで混乱しています。 Base64UWPを使用してazure mysqlデータベースに画像を保存するには

private async void button_Copy_Click(object sender, RoutedEventArgs e) 
    { 
     //create camera instance with camera capture ui 
     CameraCaptureUI captureUI = new CameraCaptureUI(); 
     captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; 
     captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); 
     StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); 
     if (photo == null) 
     { 
      // User cancelled photo capture 
      return; 
     } 
     //return the captured results to fram via bitmap 
     IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read); 
     BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); 
     SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(); 
     SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); 
     SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource(); 
     await bitmapSource.SetBitmapAsync(softwareBitmapBGR8); 
     imageControl.Source = bitmapSource; 
    } 

答えて

1

`変換イメージをしてMySQLデータベースに保存します。私は試してみました何事前

で 感謝。キャプチャされた画像をApplication Local Folderに保存し、Base64に変換します。

C#コード:私は提供すべきか、パス新しいURIで

using System.Threading.Tasks; 
using Windows.Storage; 
using Windows.Storage.Streams; 

    private async void btn_Click(object sender, RoutedEventArgs e) 
    { 
     var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/" + "your_image_name.png")); 
     string base64image = await _encodeToBase64(file.Path); 
    } 

public async Task<string> _encodeToBase64(string filePath) 
    { 
     string encode = String.Empty; 
     if (!string.IsNullOrEmpty(filePath)) 
     { 
      StorageFile file = await StorageFile.GetFileFromPathAsync(filePath); 
      IBuffer buffer = await FileIO.ReadBufferAsync(file); 
      DataReader reader = DataReader.FromBuffer(buffer); 
      byte[] fileContent = new byte[reader.UnconsumedBufferLength]; 
      reader.ReadBytes(fileContent); 
      encode = Convert.ToBase64String(fileContent); 
     } 
     return encode; 
    } 
+0

。? –

+0

@ SheikhMuhammadAmaan-Ullahこれはあなたのアプリケーションのローカルフォルダです[ここ](http://stackoverflow.com/questions/18156706/get-local-folders-from-app-winrt)です。 – Irfan

+0

キャプチャしたイメージをアプリケーションのローカル状態フォルダに保存します。 – Irfan

関連する問題