2013-11-03 73 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