XamarinでQRコード表示
Xamarinで作成中のアプリで、QRコード表示をする。 「Xamarine QR」でググってみると、読み取りの情報はよくヒットしたけど、生成の方は少なかった。
ZXing
Zxing(Zebra Crossing)というライブラリを利用した。
良いネーミングだ。。
実装
<?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:qrSample" x:Class="qrSample.MainPage" xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms" xmlns:zxcm="clr-namespace:ZXing.Common;assembly=zxing.portable"> <StackLayout> <!-- show QRcode --> <zxing:ZXingBarcodeImageView WidthRequest="300" HeightRequest="300" BarcodeValue="https://google.com" BarcodeFormat="QR_CODE"> <zxing:ZXingBarcodeImageView.BarcodeOptions> <zxcm:EncodingOptions Width="300" Height="300" /> </zxing:ZXingBarcodeImageView.BarcodeOptions> </zxing:ZXingBarcodeImageView> </StackLayout> </ContentPage>
という感じ。
BarcodeOptionsは無くても表示できるけど、なぜか少しぼやけたイメージが表示される。
- BarcodeValue="{Binding foobar}"としてバインディング可能
- WidthRequest、HeightRequestは必要