This is a migrated thread and some comments may be shown as answers.

ExportToImage pixelWith error

5 Answers 150 Views
BarCode
This is a migrated thread and some comments may be shown as answers.
Stefania
Top achievements
Rank 2
Stefania asked on 15 Nov 2016, 08:18 AM

Hi,

I was trying to add a qr into a RadFixedDocument like this

RadBarcodeQR qr = new RadBarcodeQR();
qr.Mode = QRClassLibrary.Modes.CodeMode.Byte;
qr.Text = documentHistory.SerialId.ToString();
qr.Width = 88;
qr.Height = 88;
using (MemoryStream stream = new MemoryStream())
{
      Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(qr, stream, new PngBitmapEncoder());
 
      //RadFixedDocument
       document.InsertImage(stream, area);
}

 

I have the following error on this line: Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(qr, stream, new PngBitmapEncoder());

Parameter value must be greater then 0. ParameterName: pixelWidth
 
   in System.Windows.Media.Imaging.RenderTargetBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat)
   in Telerik.Windows.Media.Imaging.ExportHelper.GetBitmapSource(FrameworkElement element, Double dpiX, Double dpiY)
   in Telerik.Windows.Media.Imaging.ExportHelper.GetElementImage(FrameworkElement element)
   in Telerik.Windows.Media.Imaging.ImageExporter.Export(FrameworkElement element, Stream stream, BitmapEncoder encoder)
   in Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(FrameworkElement element, Stream stream, BitmapEncoder encoder)
   in MileClient.DocumentUserControl.ExportAndViewDocumentWithImageStamp(DocumentHistoryEntity documentHistory) in D:\MyClient\Source\Gui\Wpf\UserControls\DocumentUserControl.xaml.cs:riga 714
   in MileClient.DocumentUserControl.OpenDocumentHistoryButton_Click(Object sender, RoutedEventArgs e) in D:\MyClient\Source\Gui\Wpf\UserControls\DocumentUserControl.xaml.cs:riga 614
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   in System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   in System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   in System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   in System.Windows.Controls.Primitives.ButtonBase.OnClick()
   in System.Windows.Controls.Button.OnClick()
   in System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   in System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   in System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   in System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   in System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   in System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   in System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   in System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   in System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   in System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   in System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   in System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   in System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   in System.Windows.Input.InputManager.ProcessStagingArea()
   in System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   in System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   in System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   in System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   in System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   in MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   in MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   in System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   in System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

5 Answers, 1 is accepted

Sort by
0
Stefania
Top achievements
Rank 2
answered on 16 Nov 2016, 08:55 AM
I have the same problem if I create the QRCode on XML and then I put Visibility to Collapsed
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 17 Nov 2016, 03:23 PM
Hello Stefania,

The reason the export extensions are getting a zero sized element, is because the RadBarcode hasn't performed the measure, arrange and layout passes. 

You can perform these manually if you don't intend to add the barcode to the visual tree. Here's your code with the added methods:

RadBarcodeQR qr = new RadBarcodeQR();
qr.Mode = QRClassLibrary.Modes.CodeMode.Byte;
qr.Text = documentHistory.SerialId.ToString();
qr.Width = 88;
qr.Height = 88;
 
qr.Measure(new Size(88, 88));
qr.Arrange(new Rect(new Size(88, 88)));
qr.UpdateLayout();
 
 
// QrCode is ready, move forward


Note, as you have seen, this is also the case when you set the Visibility to Collapsed, it is no longer in the Visual Tree and cannot be rendered into a bitmap.

Let us know if you have any further questions.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Stefania
Top achievements
Rank 2
answered on 17 Nov 2016, 03:39 PM
Thank you
0
João
Top achievements
Rank 1
answered on 04 Apr 2019, 08:44 PM
I tried to use this sample, and unfortunately the image generated is blank. Can you help?
0
Lance | Manager Technical Support
Telerik team
answered on 05 Apr 2019, 03:47 PM
Hello João,

Generally speaking, the most common reason for a blank image is the UI element hasn't been rendered yet, or the size is not not what's expected. However, I cant be sure what problem that implementation has until we've directly debugged it.

As a test, give the UIElement an explicit Height and Width and make sure the UI rendered before performing the export.

Further Assistance

So that we can give you the best support and determine an exact solution for you, can you please take the following steps:

1. Open a new Support Ticket here (you have a priority support license)
2. Provide the code that you're using and what exactly isn't working (if you can attach a runnable project that reproduces the problem, we'll be able to provide a solution more quickly)

We do try our best to answer all forum posts within a reasonable timeframe, however this is limited by available resources and workload. Whereas as Support Ticket carries a guaranteed response time. In addition, you're not able to attach a ZIP of the affected project to a public post, but you can attach it to a ticket.

Regards,
Lance | Technical Support Engineer, Principal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
BarCode
Asked by
Stefania
Top achievements
Rank 2
Answers by
Stefania
Top achievements
Rank 2
Lance | Manager Technical Support
Telerik team
João
Top achievements
Rank 1
Share this question
or