Generate Bar Code in Xamarin Forms - xamarin.forms

I need to generate a Bar Code in my Xamarin.Forms project. I have found samples to scan Bar Code. Anyone has tried to generate the Bar Code ?

With the ZXing library, you can not only scan barcodes but also generate them.
The sample repo can be found here: https://github.com/jfversluis/Blurry-ZXingBarcodeImageView and was created to answer another question here on StackOverflow about barcodes being blurry. But it also shows how to generate a barcode.
Basically, you just install the ZXing library onto your projects and add a ZXingBarcodeImageView to your page.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:BlurryZXing" x:Class="BlurryZXing.MainPage" xmlns:forms="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms" xmlns:zx="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms" xmlns:zxcm="clr-namespace:ZXing.Common;assembly=zxing.portable">
<forms:ZXingBarcodeImageView
IsVisible="True"
x:Name="QRCodeView"
BarcodeFormat="QR_CODE"
HeightRequest="300"
WidthRequest="300"
BarcodeValue="-1">
<zx:ZXingBarcodeImageView.BarcodeOptions>
<zxcm:EncodingOptions Width="300" Height="300" />
</zx:ZXingBarcodeImageView.BarcodeOptions>
</forms:ZXingBarcodeImageView>
</ContentPage>
You can specify the format and value. Supported formats at time of writing are: UPC-A, UPC-E, EAN-8, Code 39, EAN-13, ITF, RSS-14, RSS-Expanded, QR Code, Code 93, Data Matrix, Code 128, Aztec (beta), Codabar, PDF 417 (beta), MaxiCode.
Don't forget to initialize the ZXing library in your platform projects, else it will show up empty. You can do this by adding:
// On iOS in your AppDelegate.cs in the FinishedLaunching method
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
and
// On Android in the MainActivity.cs in the OnCreate method
ZXing.Net.Mobile.Forms.Android.Platform.Init();

Related

How do I extract a jpeg's EXIF thumbnail using ImageSharp?

I am trying to extract thumbnails from source jpegs and save them to the file system, using the C# ImageSharp library. I see there is some mention of it in the intellisense for the component:
SixLabors.ImageSharp.Image.Metadata.ExifProfile.CreateThumbnail()
...but I can't seem to find any documentation for it or examples to call it correctly.
I did find this:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
//method code:
Image<TPixel> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<TPixel>();
https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifProfile.html
...but I need to find where the TPixel type is to get it to work. VisualStudio doesn't recognize it and I can't seem to find a namespace or use it correctly:
"The type or namespace name 'TPixel' could not be found (are you missing a using directive or an assembly reference?)"
Legacy Windows .NET Framework could do this for System.Drawing.Image.Image.GetThumbnailImage() and it worked pretty well.
EDIT: Using tocsoft's answer, I changed the code to:
if (image.Metadata.ExifProfile != null)
{
Image<Rgba32> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();
thumbnail.Save(thumbnailPath, encoder);
}
...however, the image.Metadata.ExifProfile is null, which is unexpected since I know these source images have EXIF data.
EDIT: Actually, it's working now. Success! Thank you!
TPixel would be any of the pixel formats in the SixLabors.ImageSharp.PixelFormats namespace. But unless you are planning on interoperating with other systems that require the pixel data layed out in memory in specific ways you will likely just want to use Rgba32
Image<Rgba32> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();

Xamarin.Forms Entry reading from barcode reader with enter key gives empty result

I have a problem that is happening in Xamarin Forms UWP and perhaps also will happen in Android and iOS.
I have on XAML side a entry text field called for example textEntry.
I have on code side the definition textEntry.Completed += textEntry_Completed
on my textEntry_Completed I should have the content of the textEntry.Text.
When I write via keyboard something and press return, on the textEntry_Completed I get the textEntry.Text value correctly.
When I use a barcode scanner with keyboard emulation that after reading is also appending a return code, I get a textEntry.Text empty string inside the textEntry_Completed.
How can I solve this situation ?
Thanks,
Paulo

Data binding to SfChart properties should work with elements in StaticResource?

We have a common DateTimeAxis that we refer to in all our content pages with an SfChart.
<xForms:DateTimeAxis
x:Key="CommonDateTimeAxis"
AxisLineStyle="{StaticResource ChartAxisLineStyle}"
EdgeLabelsDrawingMode="Shift"
Interval="{Binding DateTimeAxisIntervalGrouping}"
IntervalType="{Binding DateTimeAxisInterval, Converter={StaticResource DataTimeAxisTypeConverter}}"
MajorTickStyle="{StaticResource ChartMajorTickStyle}"
Maximum="{Binding CurrentDataWindow.End}"
Minimum="{Binding CurrentDataWindow.Start}"
PlotOffset="12"
ShowMajorGridLines="False">
<xForms:DateTimeAxis.LabelStyle>
<xForms:ChartAxisLabelStyle
FontFamily="{StaticResource LightFontFamily}"
FontSize="10"
LabelFormat="{Binding DateTimeAxisDateFormat}"
TextColor="{StaticResource OffWhite}" />
</xForms:DateTimeAxis.LabelStyle>
</xForms:DateTimeAxis>
Note that we are binding to a ViewModel property as we change the format dynamically.
LabelFormat="{Binding DateTimeAxisDateFormat}"
On initial load of a page and viewmodel the setting of the format works fine. However if once we close the View\ViewModel then go back into any other of our View\ViewModels with sfChart (or the same one) the LabelFormat remains stuck on whatever value it was prior to closing the first View/ViewModel.
I thought I was doing something foolish with retaining instances but I then realised that if i simply declare the DateTimeAxis locally i.e. not a shared resource in a ResourceDictionary, the binding always works.
That's not expected right? FWIW I have opened an incident with Syncfusion seperately and will report anything useful back here
The reported issue has been fixed and moved to Syncfusion SfChart NuGet Version: 18.2.0.47

Xamarin Forms - Native Forms

I am trying to experiment with Native Forms in XF. I have this in iOS working right. That is fine.
In Android, I am getting the following error:
'MainPage' does not contain a definition for 'CreateSupportFragment' and the best extension method overload 'PageExtensions.CreateSupportFragment(ContentPage, Context)' requires a receiver of type 'ContentPage'
The code is erroring in the following code:
var _cp = new MainPage(); // my page from XF.
_list = _cp.CreateSupportFragment(this);
I have made sure that my nuget packages are up to date. I have cleaned and compiled. I've done a bunch of things, but alas, no love. Any ideas on this?
TIA
you need add the line to head of source:
using Xamarin.Forms.Platform.Android
because CreateSupportFragment is an extension method defined in it.

How can we get the list of bluetooth enabled devices in Xamarin forms application?

I have followed the following URL : https://github.com/aritchie/bluetoothle
But I didn't get that much clarity, is there anyway to get he solution a bit easily ? I just need the list of devices and RSSI....
I'm using plugin from https://github.com/xabre/xamarin-bluetooth-le. To scan the list of devices:
adapter.DeviceDiscovered += (s,a) => deviceList.Add(a.Device);
await adapter.StartScanningForDevicesAsync();
There is also a sample app in the plugin source code for reference.

Resources