我正在創建一個需要翻轉圖像的平鋪遊戲。隨着代碼我有它產生這個錯誤:從該行翻轉圖像
Exception in thread "main" java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
:
Image newImage = gc.createCompatibleImage(
image.getWidth(null),
image.getHeight(null),
Transparency.BITMASK);
這裏是編碼我有:
public Image getMirrorImage(Image image) {
return getScaledImage(image, -1, 1);
}
private Image getScaledImage(Image image, float x, float y) {
// set up the transform
AffineTransform transform = new AffineTransform();
transform.scale(x, y);
transform.translate(
(x-1) * image.getWidth(null)/2,
(y-1) * image.getHeight(null)/2);
// create a transparent (not translucent) image
Image newImage = gc.createCompatibleImage(
image.getWidth(null),
image.getHeight(null),
Transparency.BITMASK);
// draw the transformed image
Graphics2D g = (Graphics2D)newImage.getGraphics();
g.drawImage(image, transform, null);
g.dispose();
return newImage;
}
誰能向我解釋什麼,我可能需要做不同的事情,或者我可以如何讓它工作?非常感謝
嘗試將比例乘以-1而不是將其設置爲-1。 – 2011-04-10 23:16:38
爲了更快地獲得更好的幫助,請發佈[SSCCE](http://pscode.org/sscce.html)。 – 2011-04-10 23:28:26