I'm using Sqlite to save images and this is the code I use to bring they back to a simple imageView:
byte[] bookImage = books.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(bookImage, 0, bookImage.length);
holder.imageView.setImageBitmap(bitmap);
Now I'm trying to use the Picasso library to prevent a 'Out Of Memory' crash.
This is the code:
Picasso.with(holder.imageView.getContext()).load(bitmap).into(holder.imageView);
Unfortunately i cannot use load(bitmap). How can i use the Picasso library correctly for this?
You could use Glide for this:
Glide.with(holder.imageView.getContext()).load(bookImage).asBitmap().into(holder.imageView);
Related
I am using Glide library on Android to load a JPG format image into an ImageView, first I convert it to a ByteArray and then I use the following code:
GlideApp.with(context)
.load(selectedImageByteArray)
.into(image_view)
However, when the selected image orientation EXIF data is equal to "Rotate 270 CW" the image is not rotated by Glide unless I use the following code:
GlideApp.with(context)
.load(selectedImagePath)
.into(image_view)
This way I pass the selected image Uri instead of a ByteArray, why does this happen?
I attach and example (even here in Stack is not rotated):
Because that interface takes a path and nothing else. Kind of annoying since depending on the api level it is not always available. In some of the newer versions of android it is not easy to get the actual path of the file.image
data for that
The short answer is that the data that interface uses is stored in the file, not in the image data itself. There are many stack overflow links about this:
SO
I'm trying to load an image from the following url:
https://fangkarte.de:8080/fangfisch/file/files/592036af55dfffca0155e01fe10002f7
In Chrome/IE the image will be displayed without problems. When I try to load the image on Android I am not able to store the image as an PNG file. Everytime the image will be saved as a textfile which contains the image as base64 String.
Also I tried the following code but the decodedByte is null:
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Does anyone have an idea how I can show my image from the url as an bitmap or which I prefer to store the image on the device as an png?
Use Universal Image Loder to upload image from Url
Download universal image loder and add to your lib folder and
Implement the below code where you want to load image
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.noimage)
.showImageOnFail(R.drawable.icon3)
.showImageOnLoading(R.drawable.loading).build();
imageLoader.displayImage(url, imageview, options);
For handling images, Use Picasso , Glide , Universal image loader, Volley or Fresco
Eg, in picasso, you will be able to load images, store them in memory cache and handle cancellations in listviews/recyclerviews etc...
Picasso.with(context).load("https://fangkarte.de:8080/fangfisch/file/files/592036af55dfffca0155e01fe10002f7").placeholder("someimagetillyourimagedownloads).into(R.id.yourimageview);
Picasso: https://github.com/square/picasso
Glide: https://github.com/bumptech/glide
Fresco: https://github.com/facebook/fresco ( I use this after extensively testing all 3 except volley )
UIL: https://github.com/nostra13/Android-Universal-Image-Loader
Similar things can be done using all the above libraries.
I highly recommend not trying to handle images on your own. It can turn into quite a mess if you are a novice android dev.
The image you download is much to big ((860.000 bytes)) to make a Bitmap out of it. So BitmapFactory will return null.
Scale image down before use.
I'm using picasso library to download images from URL.What I need is just download the stream not a bitmap, but there is no such method in it.Is it true?
There is :
Picasso.with(this).load(URL_LONG).get(); // return bitmap
Sometimes there are some large images from URL.I need to handle them before displaying for avoiding out of memory.So I cannot load them into bitmap immediately.This is the reason i need the stream.
There is already a feature to provide what you need in Picasso Library. You can actually scale the image when you stream it. Check out this SOF Question.
I want to load an image which is located at the url "http://www.Karnatakatourism.org/mm/slide/chickmaglur_home.jpg" onto the imageview in Android.
Can anyone help me with the code to do the same?
You can use android query lib. http://code.google.com/p/android-query/wiki/ImageLoading
You just need to write
aq.id(R.id.imageview_profilee).image("your path");
You can use this one...
There many libs to do this, You can use Picasso.
Here an example of usage:
Picasso.with(context).load("http://www.karnatakatourism.org/mm/slide/chickmaglur_home.jpg").into(imageView);
Or you can use Universal Image Loader class
in which you can use by this one.
imageLoader.displayImage("http://www.karnatakatourism.org/mm/slide/chickmaglur_home.jpg", imageView, options);
I know it is possible to save bitmap to png or jpg
now i want to save bitmap to .tiff,anybody can help?
Android does not have native support for saving TIFF files.
You best bet would be to get the raw byte array, and then using either a Java or NDK library (like libtiff) to save it as a TIFF.
I believe this is is a repost from here:
Convert a bitmap image to an uncompressed tif image in Java
To answer the question, the above answer suggested the following using the Java Advanced Imaging (JAI) library:
TIFFImageWriterSpi spi = new TIFFImageWriterSpi();
ImageWriter writer = spi.createWriterInstance();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_DISABLED);
ImageOutputStream ios = ImageIO.createImageOutputStream(new File("output.tif"));
writer.setOutput(ios);
writer.write(null, new IIOImage(bmp, null, null), param);
You always can save the Bitmap as .png and convert it to .tiff
Android hasn't support for tiff images. You should use some library for working with tiff. For example my: https://github.com/Beyka/Android-TiffBitmapFactory