2011-08-26 63 views
2

我有一個android應用程序,我使用android相機拍照,然後查看照片,如果我喜歡它然後我上傳圖片到網站。imageview問題

將圖片上傳到網站我注意到有幾個像素在手機上不可見!!!在網站上圖片有一些額外的細節,在手機屏幕上不可見! !

手機屏幕上的圖片在圖像視圖中設置。

這是活動的佈局:

<ImageView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_gravity="center" 
android:scaleType="centerCrop" 
android:id="@+id/myPic" 
/> 

<Button 
android:text="Confirm Photo" 
android:layout_toLeftOf="@id/back" 
android:id="@+id/confirm" 
android:layout_marginTop="530dip" 
android:layout_height="wrap_content" 
android:layout_width="165dip" 
android:layout_alignParentRight="true" 
> 
    </Button> 

</RelativeLayout> 

這是我如何設置圖片爲imageview

Bundle extras = getIntent().getExtras(); 
    BitmapFactory.Options options=new BitmapFactory.Options(); 
    options.inSampleSize =2; 
    byte[] imageData = extras.getByteArray("imageData"); 
    Bitmap myImage = BitmapFactory.decodeByteArray(imageData , 0, imageData.length,options); 


    Matrix mat=new Matrix(); 
mat.postRotate(90); 
bitmapResult = Bitmap.createBitmap(myImage, 0, 0, myImage.getWidth(),myImage.getHeight(), mat, true); 

    Canvas c = new Canvas(bitmapResult); 
    drawTextImage(bitmapResult); 
    StoreByteImage(this, bitmapResult,100); 
ImageView imageView = (ImageView) findViewById(R.id.myPic); 
imageView.setImageBitmap(bitmapResult); 

對於額外的代碼或其他細節我在這裏把它給周到,謝謝

+1

你指的是什麼樣的額外細節? – Shlublu

+0

不會'android:scaleType =「centerCrop」'解釋裁剪? – entonio

+0

@Shlublu有一些額外的東西!我編輯了我的問題 – adrian

回答

6

如果你談論的網站比你的手機上的一個較大的圖像,則是因爲你的規模類型設置到:

android:scaleType="centerCrop" 

和您的imageview綁定可能與圖像不匹配(因此圖像被裁剪)。嘗試將此行添加到imageview,看看它是否有所作爲。

android:adjustViewBounds="true" 

最後改變你的佈局的高度和寬度屬性:

layout_width="fill_parent" 
layout_height="wrap_content" 
+0

不,它不是。我應該刪除這行:android:scaleType =「centerCrop」? – adrian

+0

看到我的編輯,它應該修復它。 – NSjonas

+0

@NSjonas ...你還沒有告訴我....應該從我的XML文件中刪除這行android:scaleType =「centerCrop」? – adrian

2

如果圖像尺寸使用scaleType屬性時,是你的ImageView的範圍之外:

android:scaleType="centerCrop" 

然後您的圖像將被裁剪並僅顯示適合您的ImageView的內容。要解決這個問題,可以調用一個幫助器方法,將圖像縮放到您需要的大小。它可能需要一些調整來適應你的情況,但它應該是有幫助的。這是一個在Strange out of memory issue while loading an image to a Bitmap object發現了一個稍作修改的版本:

public static Bitmap decodeFile(File f, int maxSize){ 
    if (f == null) 
     return null; 
    try { 
     //Decode image size 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 
     BitmapFactory.decodeStream(new FileInputStream(f),null,o); 

     //Find the correct scale value. It should be the power of 2. 
     int width_tmp=o.outWidth, height_tmp=o.outHeight; 
     int scale=1; 
     while(true){ 
      if(width_tmp/2<maxSize || height_tmp/2<maxSize) 
       break; 
      width_tmp/=2; 
      height_tmp/=2; 
      scale*=2; 
     } 

     //Decode with inSampleSize 
     BitmapFactory.Options o2 = new BitmapFactory.Options(); 
     o2.inSampleSize=scale; 
     return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); 
    } catch (FileNotFoundException e) {} 
    return null; 
} 
+0

是的,我的形象太大了。我該如何解決? – adrian

+1

^看看我的帖子 – NSjonas

+0

好主意。 +1 @NSjonas :) – Shlublu

1

根據您的問題,下面的評論,這是由android:scaleType="centerCrop"說法引起。它隱藏了圖像的邊界,因爲設備屏幕上顯示的唯一部分是適合它的部分。

NSJonas在此頁面中提供了有關如何使圖像適合屏幕的更多詳細信息。

+0

我應該刪除這行:android:scaleType =「centerCrop」?原因NSJonas沒有回答! – adrian

-1

聽起來像是要scaleType "centerInside"而不是"centerCrop"