java实现对bmp图片的旋转问题,为什么只能实现旋转一次,求解答

large2boy 2013-06-06 12:04:59
想实现对图片的旋转操作,想每按一次旋转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;
}
...全文
152 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xin_1747 2013-06-08
  • 打赏
  • 举报
回复
之前有处理过这个问题,是先把图片上的像素点的颜色的rgb值放在一个2维的数组中,然后在跟根据方向对2维数组进行处理,处理完后在把数组中的像素点的值替换原来或者生成新的图片(如果不是正方形的图片)
large2boy 2013-06-07
  • 打赏
  • 举报
回复
那么冷呢,帖子要沉啊

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧