![](/img/trans.png)
[英]How to load images from remote MySQL blob with a library like Picasso, Glide or Universal Image Loader?
[英]How to load images from remote PHP-MySQL blob with Picasso?
我有一個MySQL數據庫,其中有一些要加載到Listview的圖像。
我正在嘗試利用畢加索。 但是問題是-我該如何執行POST請求,通過(PHP中的$ _POST)發送參數,將其轉換為url,最后該庫將其加載到imageview中? 哪個是最好的選擇?
我當前用於獲取圖像的實現如下:
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
----------------------------
----------------------------
if (!"N".equalsIgnoreCase(listOfPosts.get(position).getHasImage()) ) {
if(mMemoryCache.get(postId)== null )
new GetPrimaryImages(position, holder).execute(image);
else
holder.ivPrimaryImage.setImageBitmap(mMemoryCache.get(postId));
}else {
holder.ivPrimaryImage.setImageResource(R.drawable.search);
}
return rowView;
}
GetPrimaryImages類如下所示:
public class GetPrimaryImages extends AsyncTask<Image, Void, Bitmap> {
int mPosition;
Holder mHolder;
public GetPrimaryImages(int position, Holder holder){
mPosition = position;
mHolder = holder;
}
ImageView imageView = null;
protected Bitmap doInBackground(Image... images) {
this.imageView=images[0].getImg();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("postid",(String)(this.imageView.getTag()) ));
JSONObject json;
if(mHolder.position == mPosition)
json = jsonParser.makeHttpRequest(CommonResources.getURL("get_primary_image"),
"POST", params);
else {
json = null;
cancel(true);
}
if(json == null){
//latch.countDown();
return null;
}
Log.d("Fetching Image",imageView.getTag()+ json.toString());
// check for success tag
String TAG_SUCCESS = "success";
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 0) {
image = json.getString("primaryimage");
}
} catch (JSONException e) {
e.printStackTrace();
}
return getImage(image);
}
protected void onPostExecute(Bitmap result) {
if (mHolder.position == mPosition) {
mMemoryCache.put((String) imageView.getTag(), result);
imageView.setImageBitmap(result);
}
}
}
這個
Picasso.with(context).load(url).placeholder(R.drawable.no_image).into(imageview);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.