0
我有一個運行良好的程序;但是,我希望能夠將地球圖像複製到創建的新圖像的不同部分。例如,如果我可以將地球圖片放在左下角而不是左上角。將圖像複製到特定座標
import java.awt.*;
public class CopyCatDemo
{
public static void main(String[] args)
{
Picture sourcePicture = new Picture("earth.jpg");
System.out.println("Width: " + sourcePicture.getWidth());
System.out.println("Height: " + sourcePicture.getHeight());
Picture targetPicture1 = new Picture(800,800);
targetPicture1.setAllPixelsToAColor(Color.BLACK);
Pixel sourcePixel, targetPixel = null;
Color sourceColor, targetColor = null;
for(int y = 0; y < sourcePicture.getHeight(); y++)
{
for(int x = 0; x < sourcePicture.getWidth(); x++)
{
sourcePixel = sourcePicture.getPixel(x,y);
sourceColor = sourcePixel.getColor();
targetPixel = targetPicture1.getPixel(x,y);
targetPixel.setColor(sourceColor);
}
}
sourcePicture.show();
targetPicture1.show();
targetPicture1.write("NewFile.jpg");
}//end of main method
}//end of class
因此,如果有人能請說明如何修改這個代碼來獲取地球的圖片在左下角顯示爲新的目標圖像上的例子,將不勝感激!謝謝!
什麼是'Picture'? – copeg
只需要創建一個圖片對象。類似於int如何用於整數,或者String如何用於字符串。這僅用於創建的圖片。 –
好的,那麼什麼名稱空間是'圖片'? –