這是我的計算機科學課程的一部分。其中一項任務是拍攝照片並反映出來。我已經初始化了一張名爲image的圖片。當我運行這種方法時,不是反映它反映的圖像。反映圖像
public void reflect()
{
//Creating a for loop to get all of the x values for the image object
for(int x = 0; x < image.getWidth(); x++)
{
//Creating a nested for loop to get all of the y values for each x value
for(int y = 0; y < image.getHeight(); y++)
{
//Getting a pixel object for the given x and y value
Pixel pixelObj = image.getPixel(x, y);
//I'm pretty sure this next line is where I'm screwing up.
//It's probably really simple, but I can't figure it out.
Pixel newPixel = image.getPixel(image.getWidth()-x-1, y);
//This sets the color values of the new pixel to the ones of the old pixel
newPixel.setRed(pixel0bj.getRed());
newPixel.setGreen(pixel0bj.getGreen());
newPixel.setBlue(pixel0bj.getBlue());
}
}
image.show();
}
歡迎來到SO!確保始終提出問題。我沒有看到任何問號。另外,確保你正確地標記你的問題;這是什麼語言? –
圖像的反映不是它的鏡像嗎?或者你的意思是它是錯誤軸上的鏡像? –
對不起。該語言是Java。問題是如何讓它反射而不是鏡像?我的意思是我想翻轉圖像,而不是圖像的前半部分,然後圖像的前半部分位於軸上。所以如果你有一個字母C的圖像,反射會將它變成一個向後的C,但鏡像它會使O. – LacksCreativity