简体   繁体   English

将相机中的图片加载到ImageView中

[英]Loading picture from camera into ImageView

In my app, I have it so that when the user clicks on the Camera button it takes him to the camera using an intent. 在我的应用程序中,它具有这样的功能:当用户单击“相机”按钮时,它会使用意图将他带到相机。

He then takes the picture and it should load it back into the ImageView I have on the same screen as the Camera button. 然后,他拍摄照片,并将其重新加载到与“相机”按钮相同的屏幕上的ImageView中。

I think something is wrong with my screen orientation. 我认为我的屏幕方向出了点问题。 When I load the camera view it switches to horizontal orientation, and when it closes it switches back to vertical orientation and my whole screen resets back to default. 当我加载相机视图时,它会切换为水平方向,而当我关闭相机视图时,它会切换回垂直方向,并且我的整个屏幕都会恢复为默认设置。

This is the error I get in logcat: 这是我在logcat中得到的错误:

12-03 20:14:38.440: E/SpannableStringBuilder(15134): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

Any ideas? 有任何想法吗?

EDIT: 编辑:

Here is what happens: 这是发生了什么:

  • I click on the camera button. 我单击相机按钮。
  • the screen camera view switches to horizontal mode, but I am holding it vertically so it switches to vertical. 屏幕摄像机视图会切换为水平模式,但我将其垂直握住,因此会切换为垂直模式。
  • I take the picture in horizontal mode. 我以水平模式拍摄照片。
  • The camera app asks me to save my pic or cancel it in vertical mode. 相机应用要求我保存照片或以垂直模式取消照片。
  • I click save. 我点击保存。
  • My app loads in horizontal mode and places the picture inside the imageView. 我的应用程序以水平模式加载,并将图片放置在imageView中。
  • The app then switches back to vertical mode and resets the whole screen. 然后,该应用切换回垂直模式并重置整个屏幕。

I put your alls code in, but it isn't helping. 我输入了您的alls代码,但没有帮助。

Also the point to be noted is that camera is by default in android works in landscape mode only. 另外要注意的一点是,默认情况下,相机在android中仅在横向模式下工作。 So no matter what you screen orientation is, the camera will launch in horizontal mode only. 因此,无论您的屏幕方向是什么,相机都只会在水平模式下启动。 Also as above mentioned do 还是如上所述

android:configChanges="orientation"

And handle this in your activity be using the below callback 并使用以下回调在您的活动中处理此问题

@Override
public void onConfigurationChanged(Configuration newConfig) {       
    super.onConfigurationChanged(newConfig);

} }

The reason that your activity gets reseted is because of the screen orientation change made by the camera intent. 您的活动被重置的原因是由于相机意图改变了屏幕方向。

You can put android:configChanges="orientation" inside your activity in the androidManifest.xml 您可以将android:configChanges="orientation"放入androidManifest.xml中的活动中

Once you have that, it would not destroy and recreate your activity. 一旦有了它,它就不会破坏和重新创建您的活动。

Please see http://developer.android.com/guide/topics/manifest/activity-element.html#config for more details 请参阅http://developer.android.com/guide/topics/manifest/activity-element.html#config了解更多详细信息

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

我所做的只是添加了这行代码,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM