Exemplo n.º 1
0
        // upload file to google drive
        public async Task SaveFileToDrive()
        {
            const string IMAGE_TYPE = "image/jpeg";
            const string TEXT_TYPE  = "Text/plain";
            await _service.UploadFile(DATA_FILE_NAME, TEXT_TYPE);

            await _service.UploadFile(IMAGE_FILE_NAME, IMAGE_TYPE);
        }
Exemplo n.º 2
0
        //
        private async void ClickUpload(object sender, RoutedEventArgs e)
        {
            //MessageDialog dialog = new MessageDialog("Google Drive API DLL 一直有問題,會有runtime ERROR.\n 編譯器指出問題出在GoogleDriveServiceForApp", "T^T");
            //UICommand button = new UICommand("OK");
            //dialog.Commands.Add(button);
            //await dialog.ShowAsync();
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); await renderTargetBitmap.RenderAsync(_canvas); StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync(IMAGE_NAME);

            if (file != null)
            {
                await renderTargetBitmap.RenderAsync(_canvas);

                IBuffer pixels = await renderTargetBitmap.GetPixelsAsync();

                using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);

                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)_canvas.ActualWidth, (uint)_canvas.ActualHeight, DOTS_PER_INCH, DOTS_PER_INCH, pixels.ToArray());
                    await encoder.FlushAsync();
                }
                await _service.UploadFile(IMAGE_NAME, CONTENT_TYPE);
            }
        }