java实现对bmp图片的旋转问题,为什么只能实现旋转一次,求解答
想实现对图片的旋转操作,想每按一次旋转90度,可是一下源码却只是旋转一次就不能再旋转了,求分析旋转操作 每按一次旋转90度
void xuanzhuan_actionPerformed(ActionEvent e){
try {
Image ia =ic.getImage();
int width = ia.getWidth(this);
int height = ia.getHeight(this);
int pixels[] = new int [width * height];
PixelGrabber pg = new PixelGrabber(ia, 0, 0, width, height, pixels, 0, width);
if (pg.grabPixels() && ((pg.status()& ImageObserver.ALLBITS) !=0)) {
image1 = createImage(new MemoryImageSource(height,width, rowFlipPixels(rot90Pixels(pixels, width, height), width, height), 0,height));
}
} catch (InterruptedException e1) {
e1.printStackTrace();
}
ImageIcon ica = new ImageIcon(image1);
label.setIcon(ica);
repaint();
}
private int[] rowFlipPixels(int pixels[], int width, int height) {
int newPixels[] = null;
if ((width * height) == pixels.length) {
newPixels = new int[width * height];
int newIndex = 0;
for (int y = height - 1; y >= 0; y--)
for (int x = width - 1; x >= 0; x--)
newPixels[newIndex++] = pixels[y * width + x];
}
return newPixels;
}
private int[] rot90Pixels(int pixels[], int width, int height) {
int newPixels[] = null;
if ((width * height) == pixels.length) {
newPixels = new int[width * height];
int newIndex = 0;
for (int x = width - 1; x >= 0; x--)
for (int y = 0; y < height; y++)
newPixels[newIndex++] = pixels[y * width + x];
}
return newPixels;
}
Java 图片 bmp --------------------编程问答-------------------- 那么冷呢,帖子要沉啊 --------------------编程问答-------------------- 之前有处理过这个问题,是先把图片上的像素点的颜色的rgb值放在一个2维的数组中,然后在跟根据方向对2维数组进行处理,处理完后在把数组中的像素点的值替换原来或者生成新的图片(如果不是正方形的图片)
补充:Java , Java SE