2016-08-10 3 views
0

이봐, 난 내가 어떻게 이것을 달성하기 좋은 날에 내가 XAML의 이미지를 결합 할 수 ImageSource에 그것을 변환 할 당신에게ImageSource Xamarin.Form로 이미지를 변환하는 방법

public class GenerateCode: IGenerateCode 
{ 
    ZXingBarcodeImageView barcode; 

    public ImageSource GenerateQr(string code) 
    { 
     barcode = new ZXingBarcodeImageView 
     { 
      HorizontalOptions = LayoutOptions.FillAndExpand, 
      VerticalOptions = LayoutOptions.FillAndExpand, 
     }; 
     barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE; 
     barcode.BarcodeOptions.Width = 100; 
     barcode.BarcodeOptions.Height = 100; 
     barcode.BarcodeOptions.Margin = 10; 
     barcode.BarcodeValue = code; 
     return barcode; error as barcode is an image 
    } 
} 



<Image Source={Binding imgSource} />  
감사 ZXingBarcodeImageView에서 이미지를 생성 한

답변

0

플랫폼 특정 구성 요소를 사용하여 이미지를 생성한다고 가정합니다. 이 구성 요소는 생성 된 이미지를 파일 시스템에 저장하거나 메모리에 이진 표현을 반환합니다.

파일을 ImageSource으로 변환하려면 ImageSource.FromFile()을 사용합니다. 스트림을 변환하려면 ImageSource.FromStream()을 사용하십시오.

here과 훌륭한 문서 there을 찾을 수 있습니다.

BindingContext (해당 페이지 또는 ViewModel이 중요하지 않음) ImageSource 유형의 공용 속성을 노출하고 위의 방법 중 하나를 사용하여 변환 된 이미지를 반환해야합니다. 그 대신Image을 사용하는 의미가 있기 때문에

0

클래스 ZXingBarcodeImageViewImageSource 속성을 노출하지 않습니다. XAML 또는 C# 중 하나로 배치 할 수 있습니다.

XAML :

<!-- this goes in your root node --> 
<!-- xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms" --> 

<zxing:ZXingBarcodeImageView BarcodeValue="{Binding Code}" BarcodeFormat="QR_CODE" BarcodeOptions="{Binding Options}" /> 

C#을 백엔드 :

protected override void OnAppearing() 
{ 
    BindingContext = new 
    { 
     Code = code; 
     Options = new EncodingOptions() 
     { 
      Width = 100, 
      Height = 100, 
      Margin = 10, 
     } 
    }; 
} 
예를 들어

관련 문제