2016-01-12 54 views
0

我正在应用两个旋转方程来轻松旋转灰度图像。但是,它不旋转。如何轻松旋转灰度图像

两个公式是:

x' = x *cos (theta) - y *sin (theta) 

y' = x *sin (theta) + y *cos (theta) 

我曾访问数量为Q & A的在这个网站,但解释不清楚。

IMG imgRotate(IMG output, float deg) 
{ 

    IMG lalo; 
    lalo.degree = deg; 


    float radian = ((2 *pi*output.degree)/360); 

    float cosine = cos(radian); 
    float sine = sin(radian); 
    int x1 = (output.height * sine); 
    int y1 = (output.height * cosine); 
    int x2 = (output.width * cosine + output.height* sine); 
    int y2 = (output.height* cosine -output.width * sine); 
    int x3 = (output.width * cosine); 
    int y3 =(-output.width * sine); 
    int minx = min(0, min(x1, min(x2, x3))); 
    int miny = min(0, min(y1, min(y2, y3))); 
    int maxx = max(0, max(x1, max(x2, x3))); 
    int maxy = max(0, max(y1, max(y2, y3))); 

    int w = maxx - minx; 
    int h = maxy - miny; 
    int x, y,nx,ny; 


    lalo.pixel = (unsigned char*)calloc(lalo.height*lalo.width, sizeof (unsigned char)); 

    for (y = 0; y < h; y++) 
    { 
     for (x = 0; x <w; x++) 
     { 
      nx = ceilf(x*cos(radian) - y*sin(radian)); 
      ny = ceilf(x*sin(radian) + y*cos(radian)); 

      lalo.pixel[w*ny + nx] = output.pixel[w*ny + nx]; 
     } 
    } 
    return lalo; 

} 

我加入以下代码,但它给不完整的图像

IMG imgRotate(IMG output,float deg, int height, int width) 
{ 

    IMG lalo; 
    lalo.degree = deg; 
    lalo.width = width; 
    lalo.height = height; 
    lalo.pixel=(unsigned char*)calloc (lalo.height*lalo.width, sizeof (unsigned char)); 

    float radian = ((2 *pi*lalo.degree)/360); 
    int x, y, x1, y1; 

    for (y = 0; y < lalo.height; y++) 
    { 
    for (x = 0; x <lalo.width; x++) 
    { 
     x1 = ceilf(x*cos(radian)-y*sin(radian)); 
     y1 = ceilf(x*sin(radian) + y*cos(radian)); 
     lalo.pixel[lalo.width*y1+x1] = output.pixel[output.width*x1+y1]; 
    } 
    } 
    return lalo; 
} 
+0

你的问题似乎与CSS没有关系。请说明你正在使用什么程序以及你正在尝试做什么。 –

回答

3

这是我们与css做,它可以帮助不知道

.image-class { 
 
    
 
    /* Rotate div */ 
 
    -ms-transform: rotate(45deg); /* IE 9 */ 
 
    -webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */ 
 
    transform: rotate(45deg); 
 
}
<img class="image-class" src="https://media-mediatemple.netdna-ssl.com/wp-content/uploads/images/behavioral-css/transform_rotate.png"/>

+0

亲爱的请诊断我的代码..并相应地告诉我 – bxjwxhwdc

+0

@raja,您应该能够在给出此信息的情况下将它们拼凑在一起。这些规则是您在所有三种主要浏览器类型中使用CSS旋转图像的方式。 – Araymer

+0

我不能运行它..因为我的代码没有正常运行.. – bxjwxhwdc