我有一个图像保存在我的数据库中,非常好,我可以检索它,但问题是图像质量肯定已经降低了。
这是我的代码
字符串 server_url = " http://192.168.8.100/jmiappphp/fetchImage.php?id= "+user_id;
ImageRequest imageRequest = new ImageRequest(server_url,
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
profile_image.setImageBitmap(response);
}
}, 50, 50, ImageView.ScaleType.CENTER_CROP, null, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(User_nav.this,"Something went wrong", Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
});
UserImageSingleton.getInstance(User_nav.this).addToRequestQue(imageRequest);
用户图像单例
private static UserImageSingleton mInstance;
private RequestQueue requestQueue;
private static Context mCtx;
private UserImageSingleton(Context context){
mCtx = context;
requestQueue = getRequestQueue();
}
public RequestQueue getRequestQueue(){
if(requestQueue==null){
requestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
}
return requestQueue;
}
public static synchronized UserImageSingleton getInstance(Context context){
if(mInstance==null){
mInstance = new UserImageSingleton(context);
}
return mInstance;
}
public <T> void addToRequestQue(Request<T> request){
requestQueue.add(request);
}