2014-03-29 62 views
1

我想將圖像保存到我的Azure MobileService。MobileService表格存儲圖片

我一直在環顧四周,發現你可以使用blob和azure存儲。但是,如果你可以將圖像轉換爲可存儲在普通天藍色移動服務表中的字符串或流,而不是執行此操作,我會很喜歡。

我創造我的應用程序圖像爲:

   Canvas found = null; 
       try 
       { 
        found = FindParentOfType<Canvas>(ViewInteractionCanvas.canvas); 
       } 
       catch (Exception) 
       { 
        //MessageBox.Show(e.Message.ToString(), "ERROR", MessageBoxButton.OK); 
        found = ViewInteractionCanvas.canvas; 
       } 
       WriteableBitmap writeableBitmap = new WriteableBitmap(found, null); 
       var imageBrush = new ImageBrush 
       { 
        ImageSource = writeableBitmap, 
        Stretch = Stretch.None 
       }; 
       writeableBitmap = null; 
       GC.Collect(); 

       try 
       { 
        FindChildCanvas(found, imageBrush); 
       } 
       catch (Exception e) 
       { 
        MessageBox.Show(e.Message.ToString(), AppResources.ErrorSaving, MessageBoxButton.OK); 
        return false; 
       } 
       var fileStream = new MemoryStream(); 
       writeableBitmap = new WriteableBitmap(found, null); 
       writeableBitmap.SaveJpeg(fileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 100, 100); 
       fileStream.Seek(0, SeekOrigin.Begin); 

       string tempJPEG = "My.jpg"; 
       using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
       { 
        if (myIsolatedStorage.FileExists(tempJPEG)) 
        { 
         myIsolatedStorage.DeleteFile(tempJPEG); 
        } 
        IsolatedStorageFileStream IsofileStream = myIsolatedStorage.CreateFile(tempJPEG); 
        /* 
        StreamResourceInfo sri = null; 
        Uri uri = new Uri(tempJPEG, UriKind.Relative); 
        sri = Application.GetResourceStream(uri); 

        BitmapImage bitmap = new BitmapImage(); 
        bitmap.SetSource(sri.Stream); 
        WriteableBitmap wb = new WriteableBitmap(bitmap); 
        */ 
        // Encode WriteableBitmap object to a JPEG stream. 
        //Extensions.SaveJpeg(wb, IsofileStream, wb.PixelWidth, wb.PixelHeight, 0, 85); 

        writeableBitmap.SaveJpeg(IsofileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 100, 100); 
        IsofileStream.Close(); 
       } 
       dialogResult = MessageBox.Show(AppResources.ShieldCreator_SaveShield, AppResources.ShieldCreator_SaveShieldTitle, MessageBoxButton.OKCancel); 
       if (dialogResult == MessageBoxResult.OK) 
       { 

        MediaLibrary library = new MediaLibrary(); 
        library.SavePictureToCameraRoll("picture", fileStream); 

       } 
       if (dialogResult == MessageBoxResult.Cancel) 
       { 
       } 
       fileStream.Close(); 

我在想,我可以把文件流或類似的東西?但是沒有成功。也許這完全不可能。但只是想調查的可能性,而不是開始學習一個新的概念。

希望有人能幫助。

回答

2

默認情況下,移動服務數據由SQL數據庫支持。只要你能找到一種方法在你的表中創建適當的數據類型,你就可以做到這一點。請記住:SQL數據庫數據庫被限制爲150GB,如果將數據庫實例中的內容存儲在數據庫實例中,比如存儲在您的SQL表中的blob存儲的blob存儲容量更快(這也會大大降低比SQL數據庫服務)。

+0

謝謝,Blob存儲就是這樣。但我有點不確定如何做到這一點。除了http://www.windowsazure.com/en-us/documentation/articles/mobile-services-windows-store-dotnet-upload-data-blob-storage/以外,您是否還有其他有用的信息。 – JTIM

1

你在說什麼(將圖像數據存儲在你的SQL數據庫中)是可能的,並不是很難,但絕對不推薦。存在幾個問題,包括數據的大小以及像這樣存儲數據的低效率。在一天結束的時候不過,如果這就是你要實現它,我的帖子解釋瞭如何從一個Android和iOS應用:

由於移動服務支持的數據類型,您需要將圖像數據存儲爲字符串(數據庫中的變量)。再次,遠離最有效的,但它會工作。

+0

謝謝你的幫助。然後我將不得不考慮blob存儲。我發現這個鏈接:http://www.windowsazure.com/en-us/documentation/articles/mobile-services-windows-store-dotnet-upload-data-blob-storage/你知道任何其他的幫助,只是讓我擁有所有相關信息。 – JTIM