Java 无法从base64字符串获取完整的图像质量

Java 无法从base64字符串获取完整的图像质量,java,android,mysql,bitmap,Java,Android,Mysql,Bitmap,** 我可以使用这段代码将图像保存到远程Mysql数据库中。但是我无法从这段代码中获得完整的图像质量。图像质量非常差。有人能为它提出解决方案吗 提前谢谢。 ** 请尝试以下代码: if (requestCode == SELECT_FILE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getD

** 我可以使用这段代码将图像保存到远程Mysql数据库中。但是我无法从这段代码中获得完整的图像质量。图像质量非常差。有人能为它提出解决方案吗

提前谢谢。 **

请尝试以下代码:

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, 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(){
新建异步任务(){
受保护的void onPreExecute(){
};
@凌驾
受保护字符串doInBackground(无效…参数){
BitmapFactory.Options=null;
options=新的BitmapFactory.options();
options.inSampleSize=3;
位图=BitmapFactory.decodeFile(imgPath,选项);
ByteArrayOutputStream=新建ByteArrayOutputStream();
compress(bitmap.CompressFormat.PNG,50,流);
byte[]byte_arr=stream.toByteArray();
encodedString=Base64.encodeToString(字节_arr,0);
返回“”;
}
@凌驾
受保护的void onPostExecute(字符串msg){
Log.e(“成功”、“成功”);
}
}.执行(空,空,空);
}
希望它能帮助您。

而不是使用

photo.compress(Bitmap.CompressFormat.JPEG, 90, stream);
试用

photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);

fileUri.getPath();正在显示错误。我的意思是语法错误。“imgPath”是字符串吗?它应该是一个全局变量吗?很抱歉回复得太晚了。但我很乐意帮助你。
photo.compress(Bitmap.CompressFormat.JPEG, 90, stream);
photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);