繁体   English   中英

如何以 xamarin 形式打印生成的条码 ZXING

[英]How to print Generated Barcode ZXING in xamarin forms

我设法使用 ZXING 库生成了一个条码,现在我想打印生成的条码,因为它来自 ZXingBarcodeImageView 具有相同的大小,我该怎么做

private async Task<Item>  getItem()
    {

        HttpResponseMessage _response = await _client.GetAsync(url + txt_Barcode.Text);

        if (_response.IsSuccessStatusCode)
        {
            
            string itemDetailes = await _response.Content.ReadAsStringAsync();

            return JsonConvert.DeserializeObject<Item>(itemDetailes);
             
        }
        return new Item();
    }
    private async void Btn_GetInfo(object sender, EventArgs e)
    {
       var selected_item = await getItem();
       
       // Item_barcode.Text = selected_item.Value;
        Item_Description.Text = selected_item.Description;
        Item_name.Text = selected_item.Name;
        Item_price.Text = selected_item.Price.ToString();
        item_barcode.BarcodeValue = selected_item.Value;
    }

xaml 代码

        <!--<Image HeightRequest="300" WidthRequest="300" Margin="1" x:Name="img_barcode"></Image>-->
        <zxing:ZXingBarcodeImageView x:Name="item_barcode" HeightRequest="20" WidthRequest="100" BarcodeFormat="CODE_39" BarcodeValue="Place Barcode" >
        <zxing:ZXingBarcodeImageView.BarcodeOptions>
              <zxingcomon:EncodingOptions Height="80" Width="1000"></zxingcomon:EncodingOptions>
            </zxing:ZXingBarcodeImageView.BarcodeOptions>
            
        </zxing:ZXingBarcodeImageView>
        <StackLayout Orientation="Horizontal" Spacing="20" >

            <Label TextColor="Black" x:Name="Item_Description"></Label>
            <Label TextColor="Black" x:Name="Item_price"></Label>
        </StackLayout>
        <StackLayout  x:Name="SLPrint" BackgroundColor="GhostWhite" VerticalOptions="FillAndExpand">
            <Button Text="print" BackgroundColor="Black" TextColor="White"></Button>
        </StackLayout>
    </StackLayout>
 
</StackLayout>

最好和最简单的方法是在 webview 中显示条形码。 这是一个你可以使用链接的库

您可以将脚本复制到资产文件夹中。 创建一个html文件导入脚本

现在从 xamarin 端评估 webview 中的 javascript,您可以在此处将条形码数据发送到 webview,这是您可以执行的操作。 关联

注意:您不需要进行任何自定义渲染

有了这个,您可以删除 zxing 并使您的应用程序变小

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM