2017年8月19日 星期六

for xamarin 如何繪製一二維條碼

二維的比較簡單,先講二維的好了
不用ZXing,直接用CG--CoreGraphic套件就可以了
============================================
            /*
            Correction level option as below:
            L, // Level L (Low) 7% of codewords can be restored.
    M, // Level M (Medium) 15% of codewords can be restored.
           Q, // Level Q (Quartile) 25% of codewords can be restored.
            H // Level H (High) 30% of codewords can be restored.          
             */
            CoreImage.CIQRCodeGenerator ciQrCodeGen = new CoreImage.CIQRCodeGenerator() {
                Message = NSData.FromString("這裡面可以裝下1700多個漢字,請好好發揮了"),
                CorrectionLevel = "L",
            };
            var context = CoreImage.CIContext.FromOptions(null);
            //假設有個UIImageView叫imgQrCode,放置二維條碼
            imgQrCode.Image=UIImage.FromImage(
                context.CreateCGImage(ciQrCodeGen.OutputImage,ciQrCodeGen.OutputImage.Extent)
            );
============================================

相形之下,一維比較麻煩(以39碼為例):
---------------------------step1:-------------------------------------------------------
public interface IBarcodeService {
        Stream ConvertImageStream(string text, int width = 300, int height = 130);
    }
---------------------------step2:-------------------------------------------------------
class BarcodeService : IBarcodeService {
        public Stream ConvertImageStream(string text, int width = 300, int height = 130) {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter {
                Format = ZXing.BarcodeFormat.CODE_39,
                Options = new ZXing.Common.EncodingOptions {
                    Width = width,
                    Height = height,
                    Margin = 10
                }
            };
            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            var bitmap = barcodeWriter.Write(text);
            var stream = bitmap.AsPNG().AsStream(); // this is the difference
            stream.Position = 0;

            return stream;
        }
---------------------------step3:-------------------------------------------------------
//假設我們要把一維條碼繪在UIImageView "imgCode39"上面...
var stream =new  Barcode.BarcodeService().ConvertImageStream("10607UP197419461A5B");
 imgCode39.Image= UIImage.LoadFromData(Foundation.NSData.FromStream(stream));


參考:https://forums.xamarin.com/discussion/28161/barcode-rendering-with-zxing-net-in-my-xamarin-forms-app

 大家加油了

2017年8月17日 星期四

vs2015一直說有xamarin更新,卻沒辦法update到新的版本去,如何是好

最近在用vs2015 開發mobile專案時,IDE一直說有update,也下載了,可是一直在等候安裝

(按了「安裝」也沒用,看的到吃不到令人很幹)

這時,請到:https://store.xamarin.com/account/my/subscription/downloads
登入你的xamarin account
不要點頁面中藍色的「Download Xamarin 」,是要到之下的那幾個button去各別選Xamarin.IOS & Xamarin.Android去安裝


給不想升級到vs2017的朋友參考

同場加映,
1「xamarin profiler 1.5.5」google一下就有了,在
https://developer.xamarin.com/releases/profiler/profiler-1.5/profiler-1.5.5/

2.ios simulator在
https://developer.xamarin.com/guides/cross-platform/windows/ios-simulator/
文中段「Download the installer and install on your Windows computer. Visual Studio Enterprise with Xamarin should already be installed.」那個 installer連結就有了