Reputation: 448
Please help me ,
I am not able see generated QR Code Image. What am I doing wrong !
I have used Xamarin Forms . I have Simply used a Image to be populated in StackLayout
public class BarcodePage : ContentPage
{
public BarcodePage ()
{
Image img = new Image {
Aspect = Xamarin.Forms.Aspect.AspectFit
};
img.Source = ImageSource.FromStream (() => {
var writer = new BarcodeWriter {
Format = BarcodeFormat.QR_CODE,
Options = new EncodingOptions {
Height = 200,
Width = 600
}
};
var bitmap = writer.Write ("My Content");
MemoryStream ms = new MemoryStream ();
bitmap.Compress (Bitmap.CompressFormat.Jpeg, 100, ms);
return ms;
});
var Layout = new StackLayout {
Children =
{ img}
};
Content = Layout;
}
Upvotes: 1
Views: 1046
Reputation: 8370
As you are writing the Bitmap data to the MemoryStream
using the Compress()
method the position of the stream will be at the end when you return it.
Make sure to reset the stream's position before returning it by adding this line.
ms.Position = 0;
The Image
will now read the stream from the beginning, rather than from the end.
Upvotes: 1