簡體   English   中英

裁切后設置圖像時調整ImageView的大小

[英]ImageView re-size while setting Image after Cropping

我遵循此http://www.androidhub4you.com/2012/07/how-to-crop-image-from-camera-and.html裁剪圖像。

我在拼貼框中有4-5個ImageView。在所有Imageview中,我都設置了默認圖像。單擊特定的imageview時,我從圖庫中選擇Image,然后裁剪該Image。 現在,我必須在ImageView中設置裁剪后的Image。 因此,設置裁剪后的圖像后,我的ImageView會重新調整大小,因此,其他ImageView的大小也會有所不同。 我想在Imageview中設置裁剪后的圖像時,不能調整ImageView的大小。

結果裁剪后的Image的大小可能會有所不同,因此在裁剪之前我取了ImageView Size,在裁剪后我將結果位圖縮放為與Image視圖相同的大小。

對編碼樣本進行打擊。

我正在像這樣獲取我的Imageview的高度和寬度

  viewhight = tempView.getMeasuredHeight();
    viewWidth = tempView.getMeasuredWidth();

裁剪圖像后,我會根據視圖的高度和寬度像這樣縮放圖像

Bitmap photobitmap1 = Bitmap.createScaledBitmap(photobitmap, viewWidth,viewhight, true);

之后,我將其更改為可繪制的圖像,並在Imageview上進行設置。

 Drawable drawble = new BitmapDrawable(getResources(),photobitmap1);
tempView.setBackground(drawble);

但是在設置我的視圖的高度和寬度時會被調整大小,並且由於這個接近的圖像視圖也會被調整大小,為什么我不知道。因為我將我的imageview轉換為相同的視圖大小。

我也嘗試過縮放位圖:

Bitmap photobitmap1 = Bitmap.createScaledBitmap(photobitmap, (viewWidth-30), (viewhight-30), true);

這設置位圖:

tempView.setImageBitmap(photobitmap1);
 tempView.setBackgroundColor(Color.TRANSPARENT);

但沒有任何效果。

我的xml代碼是這樣的:

   <LinearLayout
                android:id="@+id/fst"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/frame"
                android:orientation="vertical"
                android:paddingBottom="10dp"
                android:paddingLeft="85dp"
                android:paddingRight="85dp"
                android:paddingTop="10dp"
               >

                <ImageView
                    android:id="@+id/viw_1"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginBottom="2.5dp"
                    android:layout_weight="1"
                    android:background="@drawable/rec"
                 />

                <ImageView
                    android:id="@+id/viw_2"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:layout_marginTop="2.5dp"
                    android:background="@drawable/rec"
                 />
            </LinearLayout>

有人可以幫我嗎.....

您是否在XML中為imageview設置了固定的高度和寬度? 例:

<ImageView
    android:layoutWidth="60dp"
    android:layoutHeight="60dp" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM