Reputation: 10623
I am trying to load this big size image into imageview using Picasoo Library and all other library but it does not show. It can load small image but does not laod the above big size image. please help me how to load heavy image having size about 1-2Mb.
private void setImagesUsingPicasso(final String URL,final ImageView imgVW)
{
String url=URL;
//Picasso.with(getApplicationContext()).load(url).fit().centerCrop().into(imgVW);
profileProgress.setVisibility(View.VISIBLE);
Picasso.with(this).load(url).into(new Target()
{
public void onBitmapLoaded ( Bitmap bitmap, Picasso.LoadedFrom from)
{
profileProgress.setVisibility(View.INVISIBLE);
imgVW.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable arg0)
{
//Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.powered_by_google_dark);
//icon=getRoundedRectBitmap(icon, 100);
// imgVW.setImageBitmap(R);
// setImagesUsingPicasso(URL,imgVW);
}
@Override
public void onPrepareLoad(Drawable arg0)
{
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.google_map_icon_white);
//icon=getRoundedRectBitmap(icon, 100);
// imgVW.setImageBitmap(icon);
}
});
}
Upvotes: 0
Views: 1976
Reputation: 41
I suggest you give Glide a try, it's more memory efficiënt than Picasso, as Picasso loads the full image in memory while Glide loads it resized.
Also Glide uses RGB_565 instead of RGB_8888 like Picasso, which does give a slightly less high res image but consumes about 50% less memory, so that's a trade off you might want.
Also Glide is used in official google apps, just as FYI.
lastly, you can make the image fit the desired ratios of your imageview and it wont load the full image in it, but a resized version (altough you can also do that in Picasso), like this:
Glide.with(context)
.load("your url")
.override(100, 200) //give resize dimension, you could calculate thos
.centerCrop() // scale to fill the ImageView
.into(yourImageView);
more info on Glide here: Glide help
Hope this helps, let me know if you have other questions. :)
update
make sure you imported internet use in the manifest file like this:
<uses-permission android:name="android.permission.INTERNET" />
I than made an ImageView as simple as this:
<ImageView
android:id="@+id/iv_test"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
imported Glide in Gradle with this version:
compile group: 'com.github.bumptech.glide', name: 'glide', version: '3.3.1'
and than just used what i said earlier:
private void loadImg() {
ImageView ivTest = (ImageView) findViewById(R.id.iv_test);
String url = "http://pir.alphasols.com/Client_Bostwana_BuilderWorld_AndroidApp/PictureFolder/BW%20Jul17%20Mend%20pg5%20COPY-1.png";
Log.i("main","loading got called");
Glide.with(this.getBaseContext())
.load(url)
.into(ivTest);
}
didn't even use an override and it worked!
Upvotes: 0
Reputation: 69681
you can download image from url using AsyncTask
2 .try this if you dont want to use third party library
new DownloadImage(imamgeview).execute(url);
create a Async Task
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImage(ImageView bmImage) {
this.bmImage = (ImageView ) bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.d("Error", e.getStackTrace().toString());
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
i hope that it will work in your case
if it not work than i suggest you Use **WebView**
instead **ImageView**
Upvotes: 0
Reputation: 233
Working fine for me with big images
Picasso.with(this).load(/*uri*/).resize(500, 500).centerInside().into(/*ImageView*/);
Upvotes: 1