电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本
换一换
首页 金锄头文库 > 资源分类 > DOCX文档下载
分享到微信 分享到微博 分享到QQ空间

Android 解析二维码图片的两种方法介绍

  • 资源ID:52262104       资源大小:248.36KB        全文页数:13页
  • 资源格式: DOCX        下载积分:0金贝
快捷下载 游客一键下载
账号登录下载
微信登录下载
三方登录下载: 微信开放平台登录   支付宝登录   QQ登录  
二维码
微信扫一扫登录
下载资源需要0金贝
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
验证码:   换一换

 
账号:
密码:
验证码:   换一换
  忘记密码?
    
1、金锄头文库是“C2C”交易模式,即卖家上传的文档直接由买家下载,本站只是中间服务平台,本站所有文档下载所得的收益全部归上传人(卖家)所有,作为网络服务商,若您的权利被侵害请及时联系右侧客服;
2、如你看到网页展示的文档有jinchutou.com水印,是因预览和防盗链等技术需要对部份页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有jinchutou.com水印标识,下载后原文更清晰;
3、所有的PPT和DOC文档都被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;下载前须认真查看,确认无误后再购买;
4、文档大部份都是可以预览的,金锄头文库作为内容存储提供商,无法对各卖家所售文档的真实性、完整性、准确性以及专业性等问题提供审核和保证,请慎重购买;
5、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据;
6、如果您还有什么不清楚的或需要我们协助,可以点击右侧栏的客服。
下载须知 | 常见问题汇总

Android 解析二维码图片的两种方法介绍

AndroidAndroid 解析二维码图片的两种方法介绍解析二维码图片的两种方法介绍做了一个二维码扫描图片,主要是扫描不出来,看到一篇博客,其中的第二种方法可以扫描到,在此做笔记,以备后用,前面的进入相册,返回,到获取图片路径方法都一样;1.项目需求:知道项目需求,才知道先从哪里入手,见图一。(点击相册,打开图库)2.代码:1.打开图库代码:? 1 2 3 4 5 6mBtnOpenPicture.setOnClickListener(new View.OnClickListener() Override public void onClick(View v) /打开相册openGallery(); 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5);/*打开相册*/ private void openGallery() Intent picture = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXT ERNAL_CONTENT_URI);startActivityForResult(picture, PICTURE);2.获取图片路径和解析。(1). 获取图片路径:getPath(uri);由于 Android 版本不同,返回的 uri 会有所不同,需要做特殊处理。移动电玩城 http:/www.44226.net? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6SuppressLint(“NewApi“)private String getPath(Uri uri) int sdkVersion = Build.VERSION.SDK_INT;if (sdkVersion >= 19) /Log.e(“hxy“, “uri auth: “ + uri.getAuthority(); if (isExternalStorageDocument(uri) String docId = DocumentsContract.getDocumentId(uri);String split = docId.split(“:“);String type = split0;if (“primary“.equalsIgnoreCase(type) return Environment.getExternalStorageDirectory() + “/“ + split1; else if (isDownloadsDocument(uri) final String id = DocumentsContract.getDocumentId(uri);final Uri contentUri = ContentUris.withAppendedId(Uri.parse(“content:/downloads/public_down loads“), Long.valueOf(id);return getDataColumn(this, contentUri, null, null); else if (isMediaDocument(uri) final String docId = DocumentsContract.getDocumentId(uri);final String split = docId.split(“:“);final String type = split0;1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8Uri contentUri = null;if (“image“.equals(type) contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; else if (“video“.equals(type) contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; else if (“audio“.equals(type) contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;final String selection = “_id=“;final String selectionArgs = new Stringsplit1;return getDataColumn(this, contentUri, selection, selectionArgs); else if (isMedia(uri) String proj = MediaStore.Images.Media.DATA;Cursor actualimagecursor = this.managedQuery(uri, proj, null, null, null);int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) ;actualimagecursor.moveToFirst();return actualimagecursor.getString(actual_image_column_index); else if (“content“.equalsIgnoreCase(uri.getScheme() if (isGooglePhotosUri(uri)return uri.getLastPathSegment(); return getDataColumn(this, uri, null, null);/ Fileelse if (“file“.equalsIgnoreCase(uri.getScheme() return uri.getPath();return null;public static String getDataColumn(Context context, Uri uri, String selection, String selectionArgs) Cursor cursor = null;final String column = “_data“;final String projection = column ;try cursor = context.getContentResolver().query(uri, projection,selection, selectionArgs, null); if (cursor != null return cursor.getString(column_index); finally if (cursor != null)cursor.close();return null;private static boolean isExternalStorageDocument(Uri uri) return “com.android.externalstorage.documents“.equals(uri.getAuthority();public static boolean isDownloadsDocument(Uri uri) return “com.android.providers.downloads.documents“.equals(uri.getAuthority() );public static boolean isMediaDocument(Uri uri) return “com.android.providers.media.documents“.equals(uri.getAuthority();public static boolean isMedia(Uri uri) return “media“.equals(uri.getAuthority();public static boolean isGooglePhotosUri(Uri uri) return “com.google.android.apps.photos.content“.equals(uri.getAuthority();6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 8 0 8 1 8 25 8 6 8 7 8 8 8 9 9 0 9 1(2).开辟线程,解析图片,封装到 Result 中:我看了网上的 demo,大致上有 2 种方法。如下是第一种,稍后会把第二种方法也贴出来。? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27/* 解析二维码图片* param path* return*/protected Result scanningImage(String path) if (TextUtils.isEmpty(path) return null;Hashtable hints = new Hashtable();hints.put(DecodeHintType.CHARACTER_SET, “UTF-8“); / 设置二维码内容的 编码BitmapFactory.Options options = new BitmapFactory.Options();options.inJustDecodeBounds = true; / 先获取原大小scanBitmap = BitmapFactory.decodeFile(path,options);options.inJustDecodeBounds = false;int sampleSize = (int) (options.outHeight / (float) 200);if (sampleSize 注意:上面方法中有个关键的类,RGBLuminanceSource。 我把这个类的构造方法贴出来,因为我做的时候,发现网上 demo 这个类中构造传递的都是 Bitmap, 而我这个类却不是。分析传递的参数之后,我做了个转化:见如下,然后会发现报:NotFoundException. 这个异常是在 QRCodeReader 类:private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException 。(到这里我已经不是很懂了,然后又去网上搜索了下,最后自己探索出加 scanBitmap.getPixels(data, 0, scanBitmap.getWidth(), 0, 0, scanBitmap.getWidth(), scanBitmap.getHeight();),运行正常,能解析出来。? 1 2 3 4int data = new intscanBitmap.getWidth() * scanBitmap.getHeight(); /一定要加以下这个代码:/scanBitmap.getPixels(data, 0, scanBitmap.getWidth(), 0, 0, scanBitmap.getWidth(

注意事项

本文(Android 解析二维码图片的两种方法介绍)为本站会员(m****)主动上传,金锄头文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即阅读金锄头文库的“版权提示”【网址:https://www.jinchutou.com/h-59.html】,按提示上传提交保证函及证明材料,经审查核实后我们立即给予删除!

温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。

分享当前资源【Android 解析二维码图片的两种方法介绍】到朋友圈,您即可以免费下载此资源!
微信扫一扫分享到朋友圈
二维码
操作提示:任选上面一个二维码,打开微信,点击“发现”使用“扫一扫”,即可将选择的网页分享到朋友圈
您可能感兴趣的------------------------------------------------------------------------------------------------------



关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.