Java 图像预览-安卓
下面的图像是反馈部分中的Java 图像预览-安卓,java,android,user-interface,uiimageview,Java,Android,User Interface,Uiimageview,下面的图像是反馈部分中的cardwiew,目的是用户从设备的图库中选择图像并将其附加到电子邮件中,同时预览该图像。我已启动并运行了所有操作(用户成功地选择图像并将其作为附件发送)。然而,我发现自己被卡住了,不知道如何为该图像添加预览(在cardwiew的灰色部分,这是一个ImageView) 另外,除了用户从图库中挑选图像并将其附加到电子邮件的部分之外,我在编写预览部分的代码方面没有取得任何进展,并且为了保留社区指南,我发现发布无关代码是没有用的 假设您拥有相机或画廊拍摄的图像的uri: Bit
cardwiew
,目的是用户从设备的图库中选择图像并将其附加到电子邮件中,同时预览该图像。我已启动并运行了所有操作(用户成功地选择图像并将其作为附件发送)。然而,我发现自己被卡住了,不知道如何为该图像添加预览(在cardwiew
的灰色部分,这是一个ImageView
)
另外,除了用户从图库中挑选图像并将其附加到电子邮件的部分之外,我在编写预览部分的代码方面没有取得任何进展,并且为了保留社区指南,我发现发布无关代码是没有用的
假设您拥有相机或画廊拍摄的图像的uri:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
InputStream imageStream = context.getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(imageStream, null, options);
imageStream.close();
imageview.setImageBitmap(bitmap);
假设您拥有照相机或画廊拍摄的图像的uri:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
InputStream imageStream = context.getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(imageStream, null, options);
imageStream.close();
imageview.setImageBitmap(bitmap);
虽然它需要更多的调整,如缩放和旋转,以使其完美贴合,但效果很好!非常感谢。虽然它需要更多的调整,如缩放和旋转,以使其完美贴合,但效果很好!非常感谢。