2012-12-27 122 views
1

我做了一個我想放在我的活動中的一個photoshop圖像480x2500。 但是,安裝.apk後,圖像質量較差。我真的嘗試了我在google上發現的所有內容,但沒有結果。我不是一個有經驗的程序員,所以請花時間解釋一切可以幫助我的東西。 這裏是我的代碼:低質量圖像android開發

XML:

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="10dip" 
android:tileMode="repeat" 
android:dither="true"> 

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="fill_parent" 
    android:layout_height="1166dp" 
    android:adjustViewBounds="true" 
    android:scaleType="fitXY" 
    android:src="@drawable/secondbutton3" /> 

的Java代碼

import android.app.Activity; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.PixelFormat; 
import android.graphics.drawable.BitmapDrawable; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.WindowManager; 

public class Secondbutton extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 


     setContentView(R.layout.activity_secondbutton); 
     getWindow().setFormat(PixelFormat.RGBA_8888); 
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER); 

     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
     Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.secondbutton, options); 

     findViewById(R.id.imageView2).setBackgroundDrawable(new BitmapDrawable(gradient)); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_secondbutton, menu); 
     return true; 
    } 

    } 

我試圖抹掉我的形象的一小部分(有一個透明的背景),但沒有結果。 謝謝。

+0

該行是錯誤的'機器人:layout_height = 「1166dp」' – Budius

回答

1

如何從photoshop保存圖像? 透明PNG! 隨着出口的Web

+0

我保存它使用存儲爲Web和設備選項卡.png格式。 –

1

確保圖像

也被保存爲.png文件,你可能想通過Android資產工作室,這將自動調整爲不同屏幕密度的圖像來運行它。

Android Asset Studio

+0

我使用了Asset Studio,但屏幕上顯示的圖像甚至更糟。 –

0

此代碼爲我工作

BitmapFactory.Options myOptions = new BitmapFactory.Options(); 
    myOptions.inDither = true; 
    myOptions.inScaled = false; 
    myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    myOptions.inDither = false; 
    myOptions.inPurgeable = true; 
    Bitmap preparedBitmap = BitmapFactory.decodeResource(yourAppName.getSharedApplication().getResources(), 
      R.drawable.yourImage, myOptions); 
    Drawable background = new BitmapDrawable(preparedBitmap); 
    ((LinearLayout) findViewById(R.id.yourLayoutId)) 
     .setBackgroundDrawable(background);