小编Ayt*_*tee的帖子

使用Xamarin.Forms和Zxing生成QR码

我在网上看到了很多这样的帖子(旧帖子),但似乎没有什么对我有用.我正在尝试从字符串中生成QR码并将其显示在应用程序中.

这就是我在开始时所拥有的

qrCode = new ZXingBarcodeImageView
{
    BarcodeFormat = BarcodeFormat.QR_CODE,
    BarcodeOptions = new QrCodeEncodingOptions
    {
        Height  = 50,
        Width   = 50
    },
    BarcodeValue = codeValue,
    VerticalOptions = LayoutOptions.CenterAndExpand,
    HorizontalOptions = LayoutOptions.CenterAndExpand
};
Run Code Online (Sandbox Code Playgroud)

这适用于Android,但在IOS设备上它根本没有渲染.所以在研究之后我试着这样做:

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, …
Run Code Online (Sandbox Code Playgroud)

c# qr-code xamarin.ios xamarin xamarin.forms

6
推荐指数
1
解决办法
4208
查看次数

DependencyService.Get<>() not working

I'm developing an app with xamarin.forms which hase to play some sound. For that is created an interface 'IAudioPlayer'

namespace ClassLibrary.AudioPlayer
{
    public interface IAudioPlayer
    {
        void PlayAudio(string filename);
    }
}
Run Code Online (Sandbox Code Playgroud)

And in the droid project i've got the implementation like this:

using System;
using Android.Media;
using Xamarin.Forms;

[assembly: Dependency(typeof(myApp.Droid.AudioPlayer_Android))]

namespace myApp.Droid
{
    public class AudioPlayer_Android : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, ClassLibrary.AudioPlayer.IAudioPlayer, AudioTrack.IOnPlaybackPositionUpdateListener
    {
        public void PlayAudio(string filename)
        {
            var player = new MediaPlayer();
            var fd     = global::Android.App.Application.Context.Assets.OpenFd(filename);

            player.Prepared += (s, e) => …
Run Code Online (Sandbox Code Playgroud)

dependency-injection xamarin xamarin.forms

2
推荐指数
1
解决办法
2017
查看次数