Bug 47576 - Trouble with image source
Summary: Trouble with image source
Status: RESOLVED NORESPONSE
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2016-11-21 14:24 UTC by kam0u
Modified: 2017-06-20 14:28 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description kam0u 2016-11-21 14:24:22 UTC
I'm writing some native code in UWP in Xamarin Forms Application. I need to generate a QR code based on user input and show it to the user. This is the function that generates the QR code image and sets it to the image source.

public void ConvertImageStream(string text, int size)
{
   var writer = new ZXing.Mobile.BarcodeWriter
   {
      Format = ZXing.BarcodeFormat.QR_CODE,
      Options = new ZXing.Common.EncodingOptions
      {
         Height = size,
         Width = size
      },
      Renderer = new ZXing.Mobile.WriteableBitmapRenderer() { Foreground = Windows.UI.Colors.Black }
   };

   Windows.UI.Xaml.Media.Imaging.WriteableBitmap writeableBitmap = writer.Write(text);

   barcodeImage.Source = writeableBitmap;
}

The problem with this is that after loading the image to the view, it instantly throws an unhandle exception with the error: "Unable to cast object of type 'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' to type 'Windows.UI.Xaml.Media.Imaging.BitmapImage'". I have tried the same code to a new Universal App project and it works fine
Comment 1 Rui Marinho 2017-02-20 16:18:57 UTC
Thank you for taking the time to submit the bug. 
If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue, we would very much appreciate it.  
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d  

Warm regards, 
Xamarin Forms Team
Comment 2 Rui Marinho 2017-06-20 14:28:23 UTC
Because we have not received a reply to our request for more information we are
closing this issue. If you are still encountering this issue, please reopen the
ticket with the requested information. Thanks!