ExportToImage pixelWith error

6 posts, 1 answers
  1. Stefania
    Stefania avatar
    154 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
    154 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 | Technical Support Engineer, Principal
    Admin
    Lance | Technical Support Engineer, Principal avatar
    1036 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
    154 posts
    Member since:
    May 2013
  5. João
    João avatar
    1 posts
    Member since:
    Nov 2015

    Posted 04 Apr in reply to Lance | Technical Support Engineer, Principal Link to this post

    I tried to use this sample, and unfortunately the image generated is blank. Can you help?
  6. Lance | Technical Support Engineer, Principal
    Admin
    Lance | Technical Support Engineer, Principal avatar
    1036 posts

    Posted 05 Apr Link to this post

    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.
Back to Top