Zxing的使用

    public void click(View view) {
        String str = et.getText().toString().trim();
        if (TextUtils.isEmpty(str)) {
            Toast.makeText(this, "数据不能为空!!!", Toast.LENGTH_SHORT).show();
        } else {
            try {
                Bitmap bitmap = BitmapUtils.create2DCode(str);
                iv.setImageBitmap(bitmap);
            } catch (WriterException e) {
                e.printStackTrace();
            }
        }
    }

 

  • 二维码zxing使用-扫码
    public void click(View view) {
        Intent intent = new Intent(this, CaptureActivity.class);
        startActivityForResult(intent,rc);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode==rc){
            String qrcode_result = data.getStringExtra("qrcode_result");
            tv.setText(qrcode_result);
            if (qrcode_result.contains("http")){
                 /*      <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:scheme="about" />
            <data android:scheme="javascript" />
        </intent-filter>*/
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.addCategory("android.intent.category.DEFAULT");
                intent.addCategory("android.intent.category.BROWSABLE");
                intent.setData(Uri.parse("http:"+qrcode_result));
                startActivity(intent);
            }
        }
    }

 

  • 二维码zxing使用-处理扫码结果
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode==rc){
            String qrcode_result = data.getStringExtra("qrcode_result");
            tv.setText(qrcode_result);
            if (qrcode_result.contains("http")){
                 /*      <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:scheme="about" />
            <data android:scheme="javascript" />
        </intent-filter>*/
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.addCategory("android.intent.category.DEFAULT");
                intent.addCategory("android.intent.category.BROWSABLE");
                intent.setData(Uri.parse("http:"+qrcode_result));
                startActivity(intent);
            }
        }
    }

 

转载于:https://www.cnblogs.com/nangongyibin/p/10391144.html

ZXing一维码/二维码 使用文档 样例: System.IO.Stream stmYiWei = new System.IO.MemoryStream(); BitMatrix byteMatrix = new MultiFormatWriter().encode(sCode, BarcodeFormat.CODE_39, 230, 40); toBitmap(byteMatrix).Save(stmYiWei, ImageFormat.Bmp); Byte[] byteYiWei = new byte[stmYiWei.Length]; stmYiWei.Position = 0; stmYiWei.Read(byteYiWei, 0, (int)stmYiWei.Length); //将图片文件流保存为二进制文件以便保存到数据库中 System.IO.Stream stmErWei = new System.IO.MemoryStream(); IDictionary hints = new Dictionary(); hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); byteMatrix = new MultiFormatWriter().encode(sTmp, BarcodeFormat.QR_CODE, 200, 200, hints); toBitmap(byteMatrix).Save(stmErWei, ImageFormat.Bmp); Byte[] byteErWei = new byte[stmErWei.Length]; stmErWei.Position = 0; stmErWei.Read(byteErWei, 0, (int)stmErWei.Length); //将图片文件流保存为二进制文件以便保存到数据库中 strSQL = "insert into gdzc_biaoqian( bq_gd_no,bq_yiweima,bq_erweima,bq_us_no) values("; strSQL = strSQL + " @bq_gd_no,@bq_yiweima,@bq_erweima,@bq_us_no)"; SqlCommand commandImage = new SqlCommand(strSQL, connectionImage); commandImage.Parameters.Clear(); commandImage.Parameters.Add("@bq_gd_no", SqlDbType.Int).Value = Convert.ToInt32(sGdzcNo); commandImage.Parameters.Add("@bq_yiweima", SqlDbType.Image).Value = byteYiWei; commandImage.Parameters.Add("@bq_erweima", SqlDbType.Image).Value = byteErWei; commandImage.Parameters.Add("@bq_us_no", SqlDbType.Int).Value = Convert.ToInt32(Session["LoginUserID"]); commandImage.ExecuteNonQuery(); commandImage.Dispose();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值