【发布时间】:2016-01-22 21:35:29
【问题描述】:
** 我可以使用此代码将图像保存在远程 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, 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();
}
// Photo=getBytes(photo);
}
}
【问题讨论】: