MobileService表存储图片

时间:2014-03-29 22:16:49

标签: azure windows-phone-8 filestream azure-mobile-services

我想将图像保存到Azure 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 个答案:

答案 0 :(得分:2)

默认情况下,移动服务数据由SQL数据库支持。只要您能找到在表格中创建正确数据类型的方法,您就能够做到这一点。请记住:SQL数据库数据库限制为150GB,如果将内容存储在数据库实例中,比如使用存储在SQL表中的该blob的URL的blob存储,则会更快地耗尽这些数据库(这也会大大降低成本)比SQL数据库服务)。

答案 1 :(得分:1)

您正在谈论的事情(将图像数据存储在SQL数据库中)是可能的,并非完全困难,但绝对不推荐。有几个问题,包括数据的大小和这样存储数据的低效率。但是,在一天结束时,如果您想要实现它,我会发布一些帖子,说明如何通过Android和iOS应用程序执行此操作。

由于移动服务支持的数据类型,您需要将图像数据存储为字符串(数据库中的varchars)。再次,远非效率最高,但它的工作。