Issue
I have a code which getting a bitmap from url and then changing a imageview but I don't know why this not working.. I trying some similar answers but image still don't set.
This getting a bitmap.
class picture_get extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
URL img_value = null;
try {
img_value = new URL("https://graph.facebook.com/"+id+"picture?type=large");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
bitmap_pic = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
Log.i("bitmap_pic_get", "ok");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//bitmap_pic = Bitmap.createScaledBitmap(bitmap_pic, 50, 50, false);
return "Executed";
}
}
And this setting the imageview
new picture_get().execute();
runOnUiThread(new Runnable() {
@Override
public void run() {
textView1.setText("Id: "+ id);
image1.setImageBitmap(bitmap_pic);
}
});
All code working but image still the same.
Solution
This should work
class picture_get extends AsyncTask<String, Bitmap, Bitmap> {
@Override
protected Bitmap doInBackground(String... params) {
URL img_value = null;
try {
img_value = new URL("https://graph.facebook.com/"+id+"picture?type=large");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
bitmap_pic = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
Log.i("bitmap_pic_get", "ok");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//bitmap_pic = Bitmap.createScaledBitmap(bitmap_pic, 50, 50, false);
return bitmap_pic ;
}
@Override
protected void onPostExecute(Bitmap bitmap_pic) {
image1.setImageBitmap(bitmap_pic);
}
}
Answered By - Sajith Vijesekara
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.