-1
我在保存圖像位置時遇到了一些問題。我在我的應用程序中執行動畫,將圖像製作到特定位置。我想爲圖像保存這個位置並關閉應用程序,然後當我打開應用程序時,我希望在保存圖像時找到圖像。我怎樣才能做到這一點?圖像的保存/加載位置
我在保存圖像位置時遇到了一些問題。我在我的應用程序中執行動畫,將圖像製作到特定位置。我想爲圖像保存這個位置並關閉應用程序,然後當我打開應用程序時,我希望在保存圖像時找到圖像。我怎樣才能做到這一點?圖像的保存/加載位置
將它保存在一個文件中,第一個數字是x座標,第二個數字是y座標;) x的第一行和y的第二行。 你將只需要將String解析爲int。
編輯
// Saving....
DataOutputStream dos;
try {
dos = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(
new File("myFile.txt"))));
dos.writeInt(678); // x-coordinate
dos.writeInt(239); // y-coordinate
dos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Loading....
int x, y;
DataInputStream dis;
try {
dis = new DataInputStream(
new BufferedInputStream(
new FileInputStream(
new File("myFile.txt"))));
x = dis.readInt();
y = dis.readInt();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
您可以指定它嗎? – user1977348