Android 上传从gallery应用程序拍摄的图像(质量问题)
使用Android的gallery应用程序选择照片,以便稍后与httppost一起上载。照片已上载,但质量和大小都非常低。我一直在阅读有关设置位图的内容。CompressFormat.PNG将使其无损,但它正在将照片从Android 上传从gallery应用程序拍摄的图像(质量问题),android,http-post,uri,Android,Http Post,Uri,使用Android的gallery应用程序选择照片,以便稍后与httppost一起上载。照片已上载,但质量和大小都非常低。我一直在阅读有关设置位图的内容。CompressFormat.PNG将使其无损,但它正在将照片从2000x1500拍摄到250x187 有没有可能我得到的是缩略图而不是实际的图像?我正在使用谷歌的照片 代码 @Override public void onActivityResult( int requestCode, int resultCode, Intent data
2000x1500
拍摄到250x187
有没有可能我得到的是缩略图而不是实际的图像?我正在使用谷歌的照片
代码
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data ) {
super.onActivityResult( requestCode, resultCode, data );
if ( resultCode == getActivity().RESULT_OK ) {
selectedImage = Uri.parse( data.getDataString() );
try {
final Bitmap v = DecodeUriImage.Decode( selectedImage, getActivity() );
ByteArrayOutputStream bao = new ByteArrayOutputStream();
v.compress( Bitmap.CompressFormat.PNG, 100, bao );
byte[] byte_arr = bao.toByteArray();
// Add image to array
images.set( selectedImageIndex, Base64.encodeToString( byte_arr, Base64.DEFAULT ) );
} catch ( FileNotFoundException e ) {
e.printStackTrace();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
结果
位图.CompressFormat.PNG将压缩图像,但这取决于您在未压缩图像上使用的格式。您应该使用矢量图像来获得最佳效果,因为在“压缩传输”过程中,图像放大与否会降低图像质量。没有理由将所选图像放入位图中供以后使用。此外,您没有显示
DecodeUriImage.Decode(selectedImage,getActivity())中发生的一切代码>。也许它的质量在那里改变了。相反,要意识到在selectedImage
中有一个媒体路径,可以将其转换为文件系统的真实路径。保存该路径以供以后使用
如果您稍后使用它,则只需在字节数组中加载文件并对base64进行编码。不要使用Bitmapfactory