图像视图相对布局 - 更改所拍摄照片的位置



我有一个图像视图,其图像(此处)是从资产文件onCreateInstance()加载的,并且相同的图像视图旋转并加载从相机拍摄的图像这里(在拍摄的照片上使用相机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.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() 和

以下代码更新恢复上的图像视图

    @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);


        }
    }
}

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

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

问题可能出在旋转上,我相信这是在ImageView在布局中定位然后围绕其中心旋转 90 度之后发生的。在这里,旋转枢轴是视图的中心,如果它不会被旋转。

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

最新更新