-1

スクリーンショット機能を実装していて、現在はプロジェクトファイルに保存するだけですが、デスクトップなどの特定のファイルまたは場所に保存するといいでしょう。

現在:

try {
   imageId = random.nextInt(9999);
   ImageIO.write(MainGame.image, "png" , new File("Sinecure_" + imageId + ".png/"));
   System.out.println("Image Saved as Sinecure_" + imageId);
} catch (IOException e) {
   e.printStackTrace();
}
4

1 に答える 1

3

you can find the user's home directory using this code snippet:

String userHome = System.getProperty( "user.home" );

then you could (depending on the operating system) construct the file path like so:

String fullPath = userHome+File.seperator+"Desktop"+File.seperator+"Sinecure_" + imageId + ".png";
ImageIO.write(MainGame.image, "png" , new File(fullPath));

the above is for windows 7. you will need to adjust for other operating systems, of course. the easiest way to detect what OS youre running under would be another system property:

String OS = System.getProperty("os.name")
于 2013-01-13T04:59:10.230 に答える