将屏幕方向从垂直旋转到水平或反之亦然时,图像不会出现?
我使用意图从 SD 卡中选择了一张图像,选择图像后,我在图像查看器中显示了该图像,并且它正在显示,但是当我旋转屏幕时,所选图像不会出现,帮帮我吗?
我使用意图来浏览屏幕
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Choose Key Picture"), PICK_FROM_FILE);
}
并显示它
if (requestCode == PICK_FROM_FILE) {
mImageCaptureUri = data.getData();
path = getRealPathFromURI(mImageCaptureUri);
if (path == null) {
path = mImageCaptureUri.getPath();
}
if (path != null) {
bitmap = BitmapFactory.decodeFile(path);
}
}
preview.setImageBitmap(bitmap);
i selected one image from the SD card by using the intent and after selecting the image i displayed that image in an image viewer and it is showing but when i am rotating my screen the selected image is not coming,help me??
i used the intent for browsing the screen-
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Choose Key Picture"), PICK_FROM_FILE);
}
and for showing it
if (requestCode == PICK_FROM_FILE) {
mImageCaptureUri = data.getData();
path = getRealPathFromURI(mImageCaptureUri);
if (path == null) {
path = mImageCaptureUri.getPath();
}
if (path != null) {
bitmap = BitmapFactory.decodeFile(path);
}
}
preview.setImageBitmap(bitmap);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是,在屏幕旋转期间,Android 系统将重新创建您的 Activity,以使您的布局能够适应新的屏幕配置。
如果旋转屏幕后图像消失,有两种方法可以解决此问题。
第一种也是最简单的方法:将以下内容添加到清单中的 Activity 声明中:
这将告诉 Android 系统在屏幕旋转期间不要重新创建您的 Activity。
另一种方法是将图像的路径保存在 onSaveInstanceState 方法,并在活动重新创建后重新加载图像。这将帮助您解决由于内存问题而导致您的 Activity 被终止的错误(例如,如果您的应用程序正在运行并且有人调用)。此后应使用相同的重新创建过程。
无论您选择哪种方式,请仔细查看活动生命周期 文档。理解这一点是理解整个 Android 系统如何工作的关键。
The problem is that during a screen rotation the Android System will recreate your activity to enable your layout to adapt to the new screen configuration.
If the image is disappearing after you rotate the screen there are two ways to solve this problem.
First and easiest way: Add the following to the declaration of your activity in your manifest:
this will tell the Android System to not recreate your activity during the screen rotation.
The other way would be to save the path to the image in the onSaveInstanceState method in your activity and reload the image after the recreation of the activity. This will help you to solve errors in wich your activity gets killed because of memory problems (for example if your app is running and somebody calls). After this the same recreation process should be used.
Regardless of which way you are choosing have a good look at the Activity Lifecycle Documentation. Understanding this is key to understand how the whole Android System is working.
你可以在android清单中添加一些行作为onsurfacechange =“orientation”,这样你什么时候会改变你的屏幕旋转,那么什么都不会发生,所以你的图像会像以前一样
you can add some lines in android manifest as onsurfacechange="orientation" so when will you change your screen rotation than nothing will be happen so your image will be like as it was previous