2012-01-22 77 views
1

我有使用Canvas和canvas.scale(Scale,Scale)的圖像質量問題;它們看起來就像如下:使用Canvas和canvas.scale(Scale,Scale)的圖像質量問題;

機器人:在運行時

我相信我已閱讀上的圖像質量問題所有的職位調整大小位圖時,但似乎並沒有幫助調整圖像的質量當使用Canvas比例縮放(浮動比例)時。

我嘗試了許多不同的選項,如圖像質量帖子所示。

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inJustDecodeBounds = false; 
options.inDither = false; 
options.inSampleSize = 1; 
options.inScaled = false; 
options.inPreferredConfig = Bitmap.Config.ARGB_8888;//I thought this would do it 
CurrentPicture = BitmapFactory.decodeFile(path, options);//Also tried decodeStream() 


PicturePaint = new Paint(); 
//PicturePaint = new Paint(Paint.FILTER_BITMAP_FLAG); //I also tried this 
//PicturePaint = new Paint(Paint.ANTI_ALIAS_FLAG); //I also tried this 
canvas.scale(Scale, Scale); 
canvas.drawBitmap(CurrentPicture, 0, 0, PicturePaint); 

我相信這是實現我目標的最後一道屏障。如果我無法解決圖像質量問題,我很擔心,因爲我很麻煩。任何幫助表示讚賞。

謝謝!

系統不會讓我發佈圖片,所以以下是鏈接。

PictureSample

回答

3

我不沒有我的回答是否正確與否我有帆布代碼。我希望這可以幫助你。

public class FotosurpriseActivity extends Activity { 
    /** Called when the activity is first created. */ 
    Bitmap overlay; 
    Paint pTouch; 
    int X = -100; 
    int Y = -100; 
    Canvas c2; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.android); 
     Bitmap mBitmapover = BitmapFactory.decodeResource(getResources(), R.drawable.ss); 
     overlay = BitmapFactory.decodeResource(getResources(), R.drawable.ss).copy(Config.ARGB_8888, true); 
     c2 = new Canvas(overlay); 

     pTouch = new Paint(Paint.ANTI_ALIAS_FLAG); 
     // pTouch.setXfermode(new PorterDuffXfermode(Mode.TARGET); 
     pTouch.setColor(Color.TRANSPARENT); 
     pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL)); 
     setContentView(new BitMapView(this, mBitmap, mBitmapover)); 
    } 

    class BitMapView extends View { 
     Bitmap mBitmap = null; 
     Bitmap mBitmapover = null; 

     public BitMapView(Context context, Bitmap bm, Bitmap bmover) { 
      super(context); 
      mBitmap = bm; 
      mBitmapover = bmover; 
     } 

     @Override 
     public boolean onTouchEvent(MotionEvent ev) { 

      switch (ev.getAction()) { 

      case MotionEvent.ACTION_DOWN: { 

       X = (int) ev.getX(); 
       Y = (int) ev.getY(); 
       invalidate(); 

       break; 
      } 

      case MotionEvent.ACTION_MOVE: { 

       X = (int) ev.getX(); 
       Y = (int) ev.getY(); 
       invalidate(); 
       break; 

      } 

      case MotionEvent.ACTION_UP: 

       break; 

      } 
      return true; 
     } 

     @Override 
     protected void onDraw(Canvas canvas) { 
      // called when view is drawn 
      Paint paint = new Paint(); 
      paint.setFilterBitmap(true); 
      // The image will be scaled so it will fill the width, and the 
      // height will preserve the image’s aspect ration 
      /* 
      * double aspectRatio = ((double) mBitmap.getWidth())/
      * mBitmap.getHeight(); Rect dest = new Rect(0, 0, 
      * this.getWidth(),(int) (this.getHeight()/aspectRatio)); double 
      * aspectRatio2 = ((double) mBitmapover.getWidth())/
      * mBitmapover.getHeight(); Rect dest2 = new Rect(0, 0, 
      * this.getWidth(),(int) (this.getHeight()/aspectRatio2)); 
      * canvas.drawBitmap(mBitmap, null, dest, paint); 
      * canvas.drawBitmap(mBitmapover, null, dest2, paint); 
      */ 

      // draw background 
      canvas.drawBitmap(mBitmap, 0, 0, null); 
      // copy the default overlay into temporary overlay and punch a hole 
      // in it 
      c2.drawBitmap(mBitmapover, 0, 0, null); // exclude this line to show 
                // all as you draw 
      c2.drawCircle(X, Y, 80, pTouch); 
      // draw the overlay over the background 
      canvas.drawBitmap(overlay, 0, 0, null); 
     } 
    } 

} 
+1

感謝您的代碼。對此,我真的非常感激。我相信我有它的工作。我懷疑當我嘗試 PicturePaint =新的油漆(Paint.FILTER_BITMAP_FLAG); PicturePaint = new PaintPaint.ANTI_ALIAS_FLAG); 我沒有將Bitmap設置爲Bitmap.Config.ARGB_8888 – user1133277

+0

ok ................... – Ramz

0

您是否有截圖顯示您正在談論的質量問題?如果在Paint上啓用了過濾,它應該沒問題。

+0

謝謝您的回覆!對於我的回覆中的延遲,我表示抱歉。我不得不休息一下,讓大腦腫脹下降。系統不會讓我發佈圖片,所以我添加了一個圖片樣本的鏈接。我要審查我收到的其他答覆,看看他們的評論是否有幫助。 – user1133277

0

我嘗試了許多和許多代碼。 我只是在我的清單中添加了這一點,我擁有最好的質量圖像。

<uses-sdk android:minSdkVersion="9" /> 

我覺得問題是畫布是在低分辨率下創建的。如果你嘗試在屏幕上打印設備的分辨率,你可以看到它是錯誤的。 在清單中添加分辨率更改。