2017-01-26 25 views
0

我想旋转图像没有标准方法,使颜色数组和操作它,但是当我调用,旋转我得到黑点(看图片)我试图旋转没有lib,但它使黑色点在图片

enter image description here

这里是我的代码,colScaled是我试图转换成数组图片:

public void arrays() { 
    colScaled = zoom2(); 
    int j = 0; 
    int i = 0; 
    angel = Integer.parseInt(this.mn.jTextField1.getText()); 
    float degree = (float) Math.toRadians(angel); 
    float cos = (float) Math.cos(degree); 
    float sin = (float) Math.sin(degree); 
    int W = Math.round(colScaled[0].length * Math.abs(sin) + colScaled.length * Math.abs(cos)); 
    int H = Math.round(colScaled[0].length * Math.abs(cos) + colScaled.length * Math.abs(sin)); 
    int x; 
    int y; 
    int xn = (int) W/2; 
    int yn = (int) H/2; 
    int hw = (int) colScaled.length/2; 
    int hh = (int) colScaled[0].length/2; 
    BufferedImage image = new BufferedImage(W + 1, H + 1, im.getType()); 
    for (i = 0; i < colScaled.length; i++) { 
     for (j = 0; j < colScaled[0].length; j++) { 
      x = Math.round((i - hw) * cos - (j - hh) * sin + xn); 
      y = Math.round((i - hw) * sin + (j - hh) * cos + yn); 
      image.setRGB(x, y, colScaled[i][j]); 
     } 
    } 
    ImageIcon ico = new ImageIcon(image); 
    this.mn.jLabel1.setIcon(ico); 
} 
+6

[Java像素数组旋转]的可能重复(http://stackoverflow.com/questions/29739809/java-rotation-of-pixel-array) – Spektre

+0

“黑色点”在哪里?在图像中还是在图像周围? – gpasch

+0

在图像中,周围不是问题 –

回答

0

声明本块代码: -

for (i = 0; i < colScaled.length; i++) { 
    for (j = 0; j < colScaled[0].length; j++) { 
     x = Math.round((i - hw) * cos - (j - hh) * sin + xn); 
     y = Math.round((i - hw) * sin + (j - hh) * cos + yn); 
     image.setRGB(x, y, colScaled[i][j]); 
    } 
} 

xy是在图像(colScaled)像素坐标。
此代码的目的是填充目的地图像(image)中的所有像素。

在循环中,不能保证目标图像中的所有像素都将被填充,即使它位于矩形区域中。

enter image description here

上述图像描绘的问题。
请参阅?有可能不会写入目的地图像中的红色像素。

正确的解决方案是在迭代目的地图像像素,则在图像以后找到一个对应的像素。

编辑:张贴后,我只看到Spektre的评论。
我同意,这似乎是一个重复的问题。 “像素阵列”这个词让我觉得它不是。