[Phonegap+Sencha Touch] 移动开发30、phonegap的camera插件的几个问题
2014-08-20 16:53
246 查看
navigator.camera.getPicture(function(uri){ //得到拍摄的图片路径 }, function(err){}, { quality: 70, allowEdit: true, //拍摄完进行裁剪编辑 targetWidth: 250, targetHeight: 250, destinationType: navigator.camera.DestinationType.FILE_URI,//返回uri sourceType: navigator.camera.PictureSourceType.CAMERA,//拍照 saveToPhotoAlbum: true });
phonegap的camera插件,在安卓系统上存在几个问题
1、得不到拍摄的照片的真实路径,具体查看博文《移动开发29 安卓navigator.camera.getPicture得到图片的真实路径》
2、targetWidth或者targetHeight大于512像素的时候,拍照并裁剪,app就会崩溃,或者app没反应(网上有人说有的是256像素,我的魅族MX3测试了是512像素)
3、只有在targetWidth == targetHeight的时候,裁剪图片才会限制比例1:1;否则,不能限制裁剪图长和宽的比例,可以调整任意。而我们有时候就是要限制裁剪后图片的长宽比。
4、如果设置了targetWidth和targetHeight为250*250,而实际裁剪的分辨率只有100*100,裁剪得到的图片会有黑边。
解决办法:
1、第一个问题,解决办法查看博文《移动开发29 安卓navigator.camera.getPicture得到图片的真实路径》
2、第二个、第三个和第四个问题,改进如下:
进插件目录,找到此文件,org.apache.cordova.camera\src\android\CameraLauncher.java
307行附近(getImage方法):
if (targetHeight > 0 && targetWidth > 0) { //限制裁减比例 intent.putExtra("aspectX", targetWidth); intent.putExtra("aspectY", targetHeight); }
361行附近(performCrop方法):
if (targetHeight > 0 && targetWidth > 0) { //限制裁减比例 cropIntent.putExtra("aspectX", targetWidth); cropIntent.putExtra("aspectY", targetHeight); } // retrieve data on return // cropIntent.putExtra("return-data", true); cropIntent.putExtra("return-data", false); //存为文件而不返回Bitmap数据,解决裁减大图崩溃的现象 cropIntent.putExtra("scale", true); //去除黑边 cropIntent.putExtra("scaleUpIfNeeded", true); //去除黑边 File photo = createCaptureFile(encodingType); croppedUri = Uri.fromFile(photo); cropIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri); //保存裁剪图为临时文件
674行附近(onActivityResult方法):
/*注释掉下面这段代码 * Bundle extras = intent.getExtras(); // get the cropped bitmap * Bitmap thePic = extras.getParcelable("data"); if (thePic == * null) { this.failPicture("Crop returned no data."); return; } * * // now save the bitmap to a file OutputStream fOut = null; * File temp_file = new File(getTempDirectoryPath(), * System.currentTimeMillis() + ".jpg"); try { * temp_file.createNewFile(); fOut = new * FileOutputStream(temp_file); * thePic.compress(Bitmap.CompressFormat.JPEG, this.mQuality, * fOut); fOut.flush(); fOut.close(); } catch * (FileNotFoundException e) { e.printStackTrace(); } catch * (IOException e) { e.printStackTrace(); } */ File photo = createCaptureFile(encodingType); File temp_file = new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"); if (photo.exists()) photo.renameTo(temp_file); //得到裁剪图临时文件 // // Send Uri back to JavaScript for viewing image this.callbackContext .success(Uri.fromFile(temp_file).toString());
欢迎加入Sencha Touch + Phonegap 群:194182999
共同学习交流(博主QQ:479858761)
相关文章推荐
- [Phonegap+Sencha Touch] 移动开发20 IOS7状态栏问题
- [Phonegap+Sencha Touch] 移动开发18 Sencha Touch项目通过phonegap打包后的程序名字的问题
- [Phonegap+Sencha Touch] 移动开发76 让cordova app訪问远端站点也能调用cordova插件功能
- [Phonegap+Sencha Touch] 移动开发18 Sencha Touch项目通过phonegap打包后的程序名字的问题
- [Phonegap+Sencha Touch] 移动开发40 解决iOS+Phonegap+Sencha touch Cupertino主题下,只读(disabeld)输入框文字看不见的问题
- [Phonegap+Sencha Touch] 移动开发54 初次使用Android Studio遇到的2个问题
- [Phonegap+Sencha Touch] 移动开发20 IOS7状态栏问题
- [Phonegap+Sencha Touch] 移动开发64 Phonegap/Cordova 插件开发
- [Phonegap+Sencha Touch] 移动开发77 Cordova Hot Code Push插件实现自己主动更新App的Web内容
- [Phonegap+Sencha Touch] 移动开发77 Cordova Hot Code Push插件实现自动更新App的Web内容
- [Phonegap+Sencha Touch] 移动开发76 让cordova app访问远端网站也能调用cordova插件功能
- [Phonegap+Sencha Touch] 移动开发18 Sencha Touch项目通过phonegap打包后的程序名字的问题
- [Phonegap+Sencha Touch] 移动开发31 使phonegap的inappbrowser插件支持通过手机返回键进行历史记录后退
- [Phonegap+Sencha Touch] 移动开发65 iOS 9 (XCode 7) 上架之前需要做的几个步骤(解决不能联网,http请求失败)
- [Phonegap+Sencha Touch] 移动开发49 BarcodeScanner(条码/二维码)插件修改为竖屏,并美化界面(安卓版)
- [Phonegap+Sencha Touch] 移动开发67 安卓实现 新版提示更新并下载安装(自动更新插件)
- [Phonegap+Sencha Touch] 移动开发22、安卓4.0.X的webview或自带浏览器中,去除输入框外面的蓝色边框
- [Phonegap+Sencha Touch] 移动开发26 Android下的sencha touch程序,转屏时,Ext.Viewport不能触发orientationchange事件的解决办法
- [Phonegap+Sencha Touch] 移动开发2、PhoneGap初步使用
- [Phonegap+Sencha Touch] 移动开发24 打包wp8.1的App,运行时输入框聚焦弹出软键盘之后,界面上移而不恢复原位的解决办法