2009-09-01 7 views
1

임 행렬 객체와 이미지를 회전하려고하고 나는 검은 반점을 가지고 이미지를 회전 할 때 그것을 바로매트릭스 rotateAt #

를 얻을 수 없다, 그것은 하나 개의 픽셀 잘못하고 180 각도 (270)와 동일합니다 c를 각도.

90 각. 이 문제의 그림 : 이런 일이 왜 누군가가 좋은 IDE가있는 경우

public System.Drawing.Image Rotate(System.Drawing.Image image, String angle, String direction) 
{ 
    Int32 destW, destH; 
    float destX, destY, rotate; 

    destW = image.Width; 
    destH = image.Height; 
    destX = destY = 0; 

    if (r == "90" || r == "270") 
    { 
    destW = image.Height; 
    destH = image.Width; 

    destY = (image.Width - destW)/2; 
    destX = (image.Height - destH)/2; 
    } 

    rotate = (direction == "y") ? float.Parse(angle) : float.Parse("-" + angle); 

    Bitmap b = new Bitmap(destW, destH, PixelFormat.Format24bppRgb); 
    b.SetResolution(image.HorizontalResolution, image.VerticalResolution); 

    Matrix x = new Matrix(); 
    x.Translate(destX, destY); 
    x.RotateAt(rotate, new PointF(image.Width/2, image.Height/2)); 

    Graphics g = Graphics.FromImage(b); 
    g.PageUnit = GraphicsUnit.Pixel; 
    g.InterpolationMode = InterpolationMode.HighQualityBicubic; 
    g.Transform = x; 
    g.DrawImage(image, 0, 0); 

    g.Dispose(); 
    x.Dispose(); 

    return b; 
} 

말해주십시오 : 여기 http://www.spasm-design.com/rotate/onePixelWrong.jpg


그리고는 코드입니다.

좋은 하루 되세요!

+1

참고 : 천사! = 각도 ... 천사 날고, 각도가 없습니다 –

+1

@lonut : 너무 빠르지 않습니다 - Broadminded는 오래된 영어 사용자 일 수 있습니다 : http://dictionary.reference.com/browse/angle – MusiGenesis

+0

하하 나는 그것을 보지 못했지만 지금은 그것을 바꾼다. :) – Broadminded

답변

0

나는 방금이 라인에서 반올림 오류가 있다고 생각 :

x.RotateAt(rotate, new PointF(image.Width/2, image.Height/2)); 

너비와 높이가 모두 속성을 int 형입니다. 대신이 시도 :

x.RotateAt(rotate, new PointF((float)Math.Floor(image.Width/2), 
    (float)Math.Floor(image.Height/2))); 

을 (. 테스트하지,이 작동하는지 확신하지 않음)

업데이트 : 내 위의 수정이 작동합니다 생각하지 않습니다,하지만 당신을 가리킬 수 문제의 방향. 반올림을 조정하여 문제를 해결할 수없는 경우 destX를 -1로 변경하여 검은 선을 제거하면됩니다.

0

작동 방식 : x.RotateAt (rotate, new PointF (image.Width/2, image.Height/2)); 이 "image.Width/2"수익은 90 또는 270 플립 화상 인 경우 나, 각도가 무엇인지 알아

먼저 플로트 그래서 image.width = image.height 및 image.height = 폭

만약 내가 문제가 내가 이미지 너비에 대한 이미지를 회전 할 수 있습니다 누른 다음 이미지의 높이가 될 수 있으므로 이미지 x, y 좌표를 재설정해야 0,0

그래서이 "destY = (image.Width - destW)/2; " 비트 맵 에 대한 이미지 오프셋을 계산하고이 "x.Translate (destX, destY);" 비트 맵 x에 해당하는 이미지 x를 설정합니다.

하지만 회전이 잘못되어 사진이 1 픽셀 작아집니다.

그래서 내 영어 만의 최고의 메신저하지, 내가 더 질문 :

나에게 사람들을 보내 주시기 바랍니다 그리고 난 내가 무엇을 의미하는지 설명하려고거야 왜 당신이 하나를 읽을 수 있기를 바랍니다.

0

훨씬 간단한 해결책은 다음과 같습니다

  1. 이미지 주위에 하나 개의 픽셀을 추가합니다.
  2. 이미지를 회전합니다.
  3. 하나의 픽셀을 제거하십시오.

코드 :

// h and w are the width/height 
// cx and cy are the centre of the image 
myBitmap = new Bitmap(w + 2, h + 2); 
mygraphics = Graphics.FromImage(myBitmap); 
mygraphics.TranslateTransform(cx, cy); 
mygraphics.RotateTransform(angle); 
mygraphics.TranslateTransform(-cx, -cy); 
mygraphics.DrawImage(myimage, new Point(1, 1)); 

// image crop 
myBitmap= myBitmap.Clone(new Rectangle(1, 1, (int)w, (int)h), myimage.PixelFormat) 

이 주요 생각이다. 희망이 도움이됩니다.