[英]How to load images from remote PHP-MySQL blob with Picasso?
I have a MySQL db, where there are the blobs of the images I want to load to a Listview. 我有一个MySQL数据库,其中有一些要加载到Listview的图像。
I am trying to utilize Picasso. 我正在尝试利用毕加索。 But the problem is- How do I do a POST request, sending the parameters by ($_POST in PHP)-converting it to an url, and finally the library loads it into an imageview? 但是问题是-我该如何执行POST请求,通过(PHP中的$ _POST)发送参数,将其转换为url,最后该库将其加载到imageview中? Which is the best option? 哪个是最好的选择?
My current implementation for fetching the images is as follows: 我当前用于获取图像的实现如下:
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;
}
Where GetPrimaryImages class looks like this: 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);
}
}
}
Tty this 这个
Picasso.with(context).load(url).placeholder(R.drawable.no_image).into(imageview); Picasso.with(context).load(url).placeholder(R.drawable.no_image).into(imageview);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.