保存/加载图像的位置

时间:2014-06-29 14:23:40

标签: image position

我在为图片保存位置时遇到了一些问题。我在我的应用程序中有动作,将图像设置为特定位置。我想为图像保存这个位置并关闭应用程序,然后当我打开应用程序时,我希望在保存时将图像找到位置。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

将其保存在文件中,第一个数字是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();
    }