protected override void ExecuteOverride(object parameter) { this.Owner.CommitTool(); RadBitmap image = this.Owner.Image; RadUpload upload = new RadUpload(); MemoryStream stream = new MemoryStream(); PngFormatProvider png = new PngFormatProvider(); png.Export(image, stream); stream.Seek(0, SeekOrigin.Begin); RadUploadSelectedFile file = new RadUploadSelectedFile(stream, "image" + image.GetHashCode() + ".png"); upload.TargetFolder = "UploadFolder"; upload.UploadServiceUrl = "SampleUploadHandler.ashx"; upload.CurrentSession.SelectedFiles.Add(file); upload.PrepareSelectedFilesForUpload(); upload.UploadFinished += new RoutedEventHandler(upload_UploadFinished); upload.StartUpload(); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { RadBitmap radBitmap = value as RadBitmap; if (radBitmap == null) { return null; } MemoryStream stream = new MemoryStream(); PngFormatProvider provider = new PngFormatProvider(); provider.Export(radBitmap, stream); stream.Seek(0, SeekOrigin.Begin); BitmapImage bitmapImage = new BitmapImage(); #if SILVERLIGHT bitmapImage.SetSource(stream); #elif WPF bitmapImage.BeginInit(); bitmapImage.StreamSource = stream; bitmapImage.EndInit(); #endif return bitmapImage; }
/// <summary> /// Takes a UI element converts it to an image. /// </summary> /// <param name="uiElement">The uiElement to add to the manifest</param> /// <param name="customForceLayoutUpdate">A custom method to force the ui element's layout.</param> private ImageInline ConvertToImageInline(UIElement uiElement, Action customForceLayoutUpdate = null) { //To make sure the items controls render properly //add it to the BusyContent's StackPanel quickly //The BusyIndicator should be open when rendering manifests BusyContentStackPanel.Children.Add(uiElement); //Update the layout if (customForceLayoutUpdate != null) customForceLayoutUpdate(); else BusyContentStackPanel.UpdateLayout(); uiElement.Measure(new Size(double.MaxValue, double.MaxValue)); ImageInline imageInline = null; //Try to create the image inline try { var writableBitmap = new WriteableBitmap((int)uiElement.DesiredSize.Width, (int)uiElement.DesiredSize.Height); writableBitmap.Render(uiElement, null); writableBitmap.Invalidate(); var radImage = new RadBitmap(writableBitmap); var stream = new MemoryStream(); var provider = new PngFormatProvider(); provider.Export(radImage, stream); //Remove the uiElements from the stackpanel so the user does not see it BusyContentStackPanel.Children.Clear(); return new ImageInline(stream); } catch { imageInline = new ImageInline(); //Remove the uiElements from the stackpanel so the user does not see it BusyContentStackPanel.Children.Clear(); } return imageInline; }