【问题标题】:Imageview relative layout - changes position on picture takenImageview 相对布局 - 改变拍摄照片的位置
【发布时间】:2013-09-17 02:45:30
【问题描述】:

我有一个图像视图,其图像(here) 是从资产文件 onCreateInstance() 加载的,并且相同的图像视图旋转并加载了从相机here 拍摄的图像(在拍摄的照片上使用相机 API)。每次我拍一张新照片时,图像视图都会在旋转时改变位置并四处移动。

下面是相对布局结构:

<RelativeLayout 

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".MainPage" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="16dip"
    android:onClick="uploadFile"
    android:text="Upload" />

<TextView
    android:id="@+id/ins"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="26dp"
    android:text="Please scan the QR code on the package to retrieve the package ID"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<Button
    android:id="@+id/scan"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ins"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="21dp"
    android:onClick="scan"
    android:text="Scan" />

<Button
    android:id="@+id/captureFront"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="26dp"
    android:onClick="onClick"
    android:text="Camera" />

<ImageView
    android:id="@+id/result"
    android:layout_width="200dip"
    android:layout_height="150dip"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:contentDescription="@string/imageView"
    android:scaleType="fitXY"
    android:src="@drawable/ic_launcher" />

</RelativeLayout> 

以下代码显示了 imageview 如何加载图像(以编程方式)

    imageView.setImageBitmap(loadDataFromAsset());

    public Bitmap loadDataFromAsset() {
    InputStream in = null;
    try {
        in = getAssets().open("signBG.jpeg");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Bitmap bmp = BitmapFactory.decodeStream(in);
    return bmp;

}

上面的代码是通过 OnCreateInstance() 和

调用的

以下代码更新imageview onResume

    @Override
public void onResume() {
    super.onResume();
    setImage();
}

以及活动何时恢复(OnResume())

     private void setImage(){
    if(constants.picTaken){
        bitmap = loadPicture("sign.jpeg", bitmap) ;
        uploadButton = (Button)findViewById(R.id.button1);
        uploadButton.setEnabled(true);
        insLabel = (TextView)findViewById(R.id.ins);
        insLabel.setText("Please upload on confirmation");



        if (bitmap != null) {
            //Toast.makeText(this, "not null", Toast.LENGTH_SHORT).show();
            imageView.setImageBitmap(bitmap);
            imageView.setPivotX(imageView.getHeight()/2);
            imageView.setPivotY(imageView.getWidth()/2);
            imageView.setRotation(90);




        }
    }
}

请参考我链接的两张图片作为参考。 从资产文件加载时,图像看起来是否一致?

【问题讨论】:

  • 注意两个图片链接是一样的。

标签: android bitmap android-camera android-relativelayout


【解决方案1】:

这几乎是在黑暗中拍摄的,因为在问题中的链接被修复之前我看不到两张图片。

问题可能与旋转有关,我认为这是在 ImageView 定位在布局中之后发生的,然后围绕其中心旋转 90 度。如果它没有被旋转,那么旋转轴就是视图的中心。

如果是这种情况,最好的建议是旋转视图中正在使用的位图,而不是旋转视图。

【讨论】:

  • 我已经做出改变了。
  • 你在黑暗中的射击确实击中了目标
猜你喜欢
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-17
相关资源
最近更新 更多