2017-03-01 34 views
3

私はこのオンライン(古い記事)についてたくさん見てきましたが、何も私にとってはうまくいかないようです。 文字列からQRコードを生成してアプリに表示しようとしています。ここでXamarin.FormsとZxingでQRコードを生成

は、私はAndroidのための罰金に動作しますが、IOSデバイス上のすべてでレンダリングされていない初め

qrCode = new ZXingBarcodeImageView 
{ 
    BarcodeFormat = BarcodeFormat.QR_CODE, 
    BarcodeOptions = new QrCodeEncodingOptions 
    { 
     Height = 50, 
     Width = 50 
    }, 
    BarcodeValue = codeValue, 
    VerticalOptions = LayoutOptions.CenterAndExpand, 
    HorizontalOptions = LayoutOptions.CenterAndExpand 
}; 

ていたものです。 だから研究した後、私はこのようにそれを実行しようとしました:

Image qrCode; 

if (Device.OS == TargetPlatform.iOS) 
{ 
    var writer = new BarcodeWriter 
    { 
     Format = BarcodeFormat.QR_CODE, 
     Options = new ZXing.Common.EncodingOptions 
     { 
      Width = 50, 
      Height = 50 
     } 
    }; 

    var b = writer.Write(codeValue); 

    qrCode = new Image 
    { 
     Aspect = Aspect.AspectFill, 
     VerticalOptions = LayoutOptions.CenterAndExpand, 
     HorizontalOptions = LayoutOptions.CenterAndExpand, 
     Source = ImageSource.FromStream(() => 
     { 
      MemoryStream ms = new MemoryStream(b); 
      ms.Position = 0; 
      return ms; 
     }) 
    }; 

}else{ 
    qrCode = new ZXingBarcodeImageView 
    { 
     BarcodeFormat = BarcodeFormat.QR_CODE, 
     BarcodeOptions = new QrCodeEncodingOptions 
     { 
      Height = 50, 
      Width = 50 
     }, 
     BarcodeValue = codeValue, 
     VerticalOptions = LayoutOptions.CenterAndExpand, 
     HorizontalOptions = LayoutOptions.CenterAndExpand 
    }; 
} 

Content = new StackLayout 
{ 
    Children = { 
     header, lblExplenationText, qrCode 
    }, 
    BackgroundColor = Color.White 
}; 

しかし、すべてでレンダリングは何も残っていません。

ZXing.Mobile.Forms NuGetパッケージのバージョン:2.1.47(最新)

+0

あなたは解決策を見つけましたか?そうでない場合、私はあなたが賞金を開始するのを手伝うことができます – knocte

答えて

1

知らissueのようです。
は幸いにもHeightRequest & WidthRequestを設定するための回避策は、あり、ここでは作業コード例を次に示します。

ZXingBarcodeImageView GenerateQR(string codeValue) 
{ 
    var qrCode = new ZXingBarcodeImageView 
    { 
     BarcodeFormat = BarcodeFormat.QR_CODE, 
     BarcodeOptions = new QrCodeEncodingOptions 
     { 
      Height = 350, 
      Width = 350 
     }, 
     BarcodeValue = codeValue, 
     VerticalOptions = LayoutOptions.CenterAndExpand, 
     HorizontalOptions = LayoutOptions.CenterAndExpand 
    }; 
    // Workaround for iOS 
    qrCode.WidthRequest = 350; 
    qrCode.HeightRequest = 350; 
    return qrCode; 
} 
関連する問題