如何将坐标和图像保存到整数变量中?

问题描述:

对于我的项目,我需要能够放置图像,然后将坐标x,y和图像名称“保存”到一个整数。整数然后被放入一个数组中。所以如果数组被调用,它会给出一个图像名称和整数坐标。如何将坐标和图像保存到整数变量中?

sticker [] placedsticker = new sticker [20]; 
    int slot = 0; 
    int placedpic; 
    else if (bluntSoundPlay){ //else if bluntSound is true 
     EZ.addImage("blunt.png", clickX, clickY); //a blunt will be placed 
     bluntsound.play(); //and blunt sound will play 
     placedpic = 0;//each image has a different placed picnumber. ex. 0, 1, 2, 3. 
     slot ++;//int slot increments every time image is placed so if it is at 1, it will fill in slot 0 of the array. If slot is 2 it will fill in slot 1 of the array. 
       } 

我该如何将所有这些信息保存到定位图整数?另外,我如何将插槽1放入阵列插槽0?

+0

难道这就是用来保存所有到一个变量/整数? – user5329697

+4

这甚至意味着什么?将所有内容保存为整数! – QuakeCore

+2

如果您或其他人可以弄清楚如何将图像存储为32位整数,然后将其恢复,我会付出高昂的代价;)请澄清您的作业要求。 – hotzst

也许你打算说你想保存一个图像名称和坐标在一个数组中。与将它们保存在数组中的整数不同。

你可以有一个SortedSet的(ImageName,X,Y),然后简单的添加该对象数组?这是你想要达到的目标吗?

你要首先创建一个对象来保存数据:

class ImageData { 
    public String name; 
    public int x; 
    public int y; 

    public ImageData(String name, int x, int y) { 
     this.name = name; 
     this.x = x; 
     this.y = y; 
    } 
} 

然后将它们添加到列表:

Vector v = Vector(); 
ImageData image = ImageData("cat.jpg", 0, 0); 
v.add(image); 
+0

我有这样的东西'sticker [] placedsticker = new sticker [20]; '保存我的数据。它创建了20个可以存储我的信息的空间。 – user5329697

+0

@ user5329697而你的'sticker'有你的图像名称,x坐标和y坐标的字段? –

+0

这是我的贴纸班。 '公共类贴纸{ \t EZImage image; \t INT X = -100; //将这个图象戏外 \t INT Y = -100; \t EZSound声音; \t String imageName; \t \t贴纸(字符串文件名,字符串newSound,INT下一页末,INT newY){ \t \t \t图像= EZ.addImage(文件名,X,Y); \t \t \t imageName = fileName; \t \t \t setPosition(newX,newY); \t \t \t sound = EZ.addSound(newSound); \t \t} \t \t空隙setPosition两种(INT下一页末,INT newY){ \t \t \t X =下一页末; \t \t \t y = newY; \t \t \t图片。translateTo(newX,newY); \t \t} \t \t INT getXPosition(){ \t \t \t返回X; \t \t} \t \t INT getYPosition(){ \t \t \t返回ÿ; \t \t} } ' – user5329697