我需要从解析中提取所有图像,我有这个代码,但它只返回给我最后一个图像,我如何获得特定图像或根据已连接的用户
public void PullImage(){
progressDialog = ProgressDialog.show(this, "", "Downloading Image...", true);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("User");
// query.whereEqualTo("Column", bitmap);
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object != null) {
ParseFile file = (ParseFile) object.get("ImageFile");
file.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
progressDialog.dismiss();
} else {
// something went wrong
}
}
});
} else {
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT).show();
}
}
});
}
答案 0 :(得分:0)
尝试以下方法 -
import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class CompressBitmap {
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and
// keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
public static Bitmap decodeSampledBitmapFromResourceMemOpt(
InputStream inputStream, int reqWidth, int reqHeight) {
byte[] byteArr = new byte[0];
byte[] buffer = new byte[1024];
int len;
int count = 0;
try {
while ((len = inputStream.read(buffer)) > -1) {
if (len != 0) {
if (count + len > byteArr.length) {
byte[] newbuf = new byte[(count + len) * 2];
System.arraycopy(byteArr, 0, newbuf, 0, count);
byteArr = newbuf;
}
System.arraycopy(buffer, 0, byteArr, count, len);
count += len;
}
}
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(byteArr, 0, count, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
options.inPurgeable = true;
options.inInputShareable = true;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
// int[] pids = { android.os.Process.myPid() };
// MemoryInfo myMemInfo = mAM.getProcessMemoryInfo(pids)[0];
// Log.e(TAG, "dalvikPss (decoding) = " + myMemInfo.dalvikPss);
return BitmapFactory.decodeByteArray(byteArr, 0, count, options);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
CompressBitmap.java -
apt-get remove imagemagick-common