2011-08-12 45 views
0

我要旋转我像更多的时间,我不能这样做在的onDraw方法,我的代码是:旋转图像,但图像色彩暗淡和图像变形

  options = new BitmapFactory.Options(); 
    options.inScaled = false; 
    options.inJustDecodeBounds = false; 
    options.inDither = false; 

    options.inScaled = false; 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 

     public void setAddBmpImage(int rotate) { 

    byte[] by = getBitmapByte(rotatedBitmap); 
    Bitmap source = BitmapFactory.decodeByteArray(by, 0, by.length, options); 

    Bitmap bmpSephia = Bitmap.createBitmap(rotatedBitmap.getWidth(), rotatedBitmap.getHeight(), Bitmap.Config.ARGB_8888); 
    Canvas canvas = new Canvas(bmpSephia); 
    canvas.rotate(rotate); 
    canvas.drawBitmap(source, 0, 0, null); 
    rotatedBitmap= bmpSephia; 
    imageStartX = (screenWidth/2 - rotatedBitmap.getWidth()/2); 
     imageStartY = (screenHeight/2 - rotatedBitmap.getHeight()/2); 
     invalidate(); 

} 

通过图像十分旋转好了,但图像变形,这是非常丑陋的,你能告诉我为什么,并给我一个很好的方法,谢谢使用

回答

1

尝试setAntiAlias(true)

Canvas canvas = new Canvas(bmpSephia); 
canvas.rotate(rotate); 
Paint paint = new Paint(); 
paint.setAntiAlias(true); 
canvas.drawBitmap(source, 0, 0, paint); 

或者

BitmapDrawable bmdraw = new BitmapDrawable(bmpSephia); 
bmdraw.setAntiAlias(true); 
Canvas canvas = new Canvas(bmdraw.getBitmap()); 
canvas.rotate(rotate); 
+0

后来我会尝试,然后给出结果 – pengwang

+0

我尝试你的方法,这是没有用的 – pengwang