2013-02-23 30 views
0

我想使用畫布顯示圖像.png,但出於某種原因,我無法讓它工作,圖像不反鋸齒。這使得它在曲線或對角線上都很像。圖像不使用畫布反別名

這是代碼我使用:

Pixmap button = g.newPixmap("button.png"); 


@Override 
public Pixmap newPixmap(String fileName) { 
    Config config = Config.ARGB_8888; 

    Options options = new Options(); 
    options.inPreferredConfig = config; 

    InputStream in = null; 
    Bitmap bitmap = null; 
    try { 
    in = manager.open(fileName); 
    bitmap = BitmapFactory.decodeStream(in, null, options); 
    if (bitmap == null) 
     throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); 
    } catch (IOException e) { 
    throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); 
    } finally { 
    if (in != null) { 
     try { 
     in.close(); 
     } catch (IOException e) { 
     } 
    } 
    } 

    return new Pixmap(bitmap); 
} 

g.drawPixmap(button); 

@Override 
public void drawPixmap(Pixmap pixmap) { 
    srcRect = new Rect(0, 0, pixmap.getOriginalWidth(), pixmap.getOriginalHeight()); 
    dstRect = new Rect(pixmap.getX(), pixmap.getY(), pixmap.getX() + pixmap.getVirtualWidth(), pixmap.getY() + pixmap.getVirtualHeight()); 
    canvas.drawBitmap(pixmap.bitmap, srcRect, dstRect, paint); 
} 

什麼可能我是做錯了什麼?

回答

0

嘗試:

paint.setAntiAlias(true); 
paint.setFilterBitmap(true); 
paint.setDither(true); 

或者:

Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); 
+0

,其實我做的圖像顯示效果較好,但仍表現出一定的像素化的曲線(較少,但它仍然顯示)。這可能是一些設計問題(也許是我應該使用的Photoshop中的某種技術,或者如此..)或者是否有我應該激活的任何設置? – AnnaSpart 2013-02-24 15:39:17

+0

呃...是適合該設備的圖像的分辨率?你使用hdpi,xhdpi可繪製文件夾嗎? – Ixx 2013-02-24 19:02:11

+0

是的,我使用的是高分辨率設備的大分辨率,而我使用的是可繪製的文件夾 – AnnaSpart 2013-02-24 19:08:47