ExportToImage pixelWith error

4 posts, 1 answers
  1. Stefania
    Stefania avatar
    120 posts
    Member since:
    May 2013

    Posted 15 Nov 2016 Link to this post

    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)
  2. Stefania
    Stefania avatar
    120 posts
    Member since:
    May 2013

    Posted 16 Nov 2016 in reply to Stefania Link to this post

    I have the same problem if I create the QRCode on XML and then I put Visibility to Collapsed
  3. Answer
    Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    462 posts

    Posted 17 Nov 2016 Link to this post

    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!
  4. Stefania
    Stefania avatar
    120 posts
    Member since:
    May 2013

    Posted 17 Nov 2016 in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Thank you
Back to Top