2013-11-03 72 views
0

我使用parse.com,检索图像时出现问题。这是代码:问题从parse.com中检索图像android

ParseFile fileObject = (ParseFile) comment.get("ac"); 
      fileObject.getDataInBackground(new GetDataCallback() { 

         @Override 
         public void done(byte[] data, 
           ParseException e) { 
          if (e == null) { 

           // Decode the Byte[] into 
           // Bitmap 
           try { 
           Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length); 

           // Get the ImageView from 
           // main.xml 
           String root = Environment.getExternalStorageDirectory().toString(); 
           File myDir = new File(root + "/imagesuri1/");  


           String fname = "image-"+ n +".jpg"; 

           n++; 
           File file = new File (myDir, fname); 
           if (file.exists()) 
            {file.delete();} 

             FileOutputStream out = new FileOutputStream(file); 
             bmp.compress(Bitmap.CompressFormat.JPEG, 90, out); 

             out.flush(); 
             out.close(); 
           } catch (Exception b) { 
             b.printStackTrace(); 
           } 
           // Close progress dialog 

           progressDialog.dismiss(); 
          } 
         else { 
     Toast.makeText(getApplicationContext(), "ha abido un problema", Toast.LENGTH_SHORT).show(); 
          } 

         } 



        }); 
     } 
     } 


    }); 

no++; 

具体来说,问题是,我在parse.com 3个图像,我检索所有的图像,解码,并将其保存在SD卡上。有时图像像这样返回: (image-0.jpg - 0)(image-1.jpg - 1)(image-2.jpg - 2)。这就是我要的。有时图像会像这样返回:(image-0.jpg - 0)(image-2.jpg - 1)(image-1.jpg - 2)。我不明白为什么。

这是文件的大小检索问题吗?请帮助我的建议或解决方案,因为我真的不明白为什么它给了我这个结果(混乱),如果我正确地命令我的查询谢谢。

回答

0

我没有看到您的代码查询,但它可能是您的订购问题引入的地方。

尝试把下面的逻辑到查询给力的图像的顺序是由“交流”字段:

// Sorts the results in ascending order by the ac field 
query.orderByAscending("ac"); 

更多信息,请参见Query Constraints section of the Parse Android Docs