**
我可以使用这段代码将图像保存在远程MysqL数据库中.但是我无法从这段代码中获得完整的图像质量.图像质量非常差.有人建议解决它吗?
提前致谢.
**
public voID onActivityResult(int reqCode,int resCode,Intent data) { if (resCode == RESulT_OK) { if (reqCode == 1) { Bitmap photo = null; imageURI = data.getData(); try { photo = MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageURI); } catch (IOException e) { e.printstacktrace(); } Image.setimageBitmap(photo); ByteArrayOutputStream stream = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.JPEG,90,stream); //compress to which format you want. byte[] byte_arr = stream.toByteArray(); String image_str = Base64.encodetoString(byte_arr,Base64.DEFAulT); try { image_str1 = URLEncoder.encode(image_str,"UTF-8"); } catch (UnsupportedEnCodingException e) { e.printstacktrace(); } } } if (reqCode == CAMERA_REQUEST && resCode == RESulT_OK) { Bitmap photo = (Bitmap) data.getExtras().get("data"); Image.setimageBitmap(photo); ByteArrayOutputStream stream = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.JPEG,stream); //compress to which format you want. byte[] byte_arr = stream.toByteArray(); String image_str = Base64.encodetoString(byte_arr,Base64.DEFAulT); try { image_str1 = URLEncoder.encode(image_str,"UTF-8"); } catch (UnsupportedEnCodingException e) { e.printstacktrace(); } // Photo=getBytes(photo); } }
最佳答案试试以下代码:if (requestCode == SELECT_file && resultCode == RESulT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage,filePathColumn,null,null); cursor.movetoFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); imgPath = cursor.getString(columnIndex); cursor.close();}else if (requestCode == REQUEST_CAMERA && resultCode == RESulT_OK ) { imgPath = fileUri.getPath(); if (imgPath != null && !imgPath.isEmpty()) { encodeImagetoString(); } else { Toast.makeText(getApplicationContext(),getResources().getString(R.string.some_error_occured),Toast.LENGTH_LONG).show(); }}
encodeImagetoString()
public voID encodeImagetoString() { new AsyncTask
希望它会对你有所帮助. 总结
以上是内存溢出为你收集整理的java – 无法从base64字符串获得完整的图像质量全部内容,希望文章能够帮你解决java – 无法从base64字符串获得完整的图像质量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)