How to create image getting URL from JSON - java

I have an app that retrieves data from json, including the URL of the image I want to display in my app.
How exactly do I create an image with that URL?
I've been searching the web and found some third-party libraries (Glide & Picasso) but I was hoping there was a way to do it without those libraries.

It is strongly recommended third-party libraries (I prefer Picasso). It is more that just downloading the image. Functionalities like local storage to avoid unnecessary data transfer are too good to ignore, also complex enough to create from scratch...
But if you still want to do it manually try this:
URL url = new URL("www.yourimagepathgoeshere.com");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);
If you also need JSON parser, try JSONSimple.

You can use it by downloading the image from its url and then making Bitmap of the saved image path and then setting it to your imageview using:-
imageView.setImageBitmap(yourBitmap);
But, i will prefer you to use the 3rd party libraries instead for this
purpose as they manages everything efficiently from downloading of
images in multiple threads to Bitmap Handling for memory efficient
implementation.

Easy way is use picasso or glide libraries.
But u can try this Accepted Answer link

Related

Downloading images from url and saving them on disk with Picasso

My app is downloading images with Picasso like this:
Picasso.with(getBaseContext()).load("https://www.sestavsisvujsvet.cz/files/magnetky/"+id+".png").placeholder(R.drawable.magnetka_placeholder).error(R.drawable.magnetka_placeholder).into(obrazek);
and it works well, but I need to save images to disk, because Picasso's caching mechanism isn't enough (I have up to 870 images which will be frequently seen by the user).
Is there any way to download the image, store it and load it from disk later?
I tried to find some solution to this, but I wasn't able to find anything useful.
Maybe it would be better to download them without Picasso, but I am not sure if it's possible.
I don't mind replacing Picasso completely and using another library, as long as it's capable of saving the images.
Thanks!
Please have a look at this for downloading image.
There are some changes in getting android storage for that please have a look here
After downloading images you need to manage them locally, use sqlite for keeping track of your files.
Basically you need to download images, and after success, save entry in Database which will include fields like location, file_name, create_on, etc. Now you can get images from database
Hope this will help!

Is it possible to use image loading library with odoo mobile framework

I am working on an app base on odoo mobile framework , I find trouble with fetching images from server (which done with base 64 encode/decode) , I am trying to involve one of the image loading library (Glide, Picasso .etc) to do the work (easier, more efficient, help me to optimize usage data/wifi ). The problem is the framework use "authentication" in all its requests , and without this authentication Glide couldn't upload images from server. Any one have an idea how to overcome this problem?
Yes, you can display image(attachment) using any lazy loading library using below syntax for URL for attachment using id
http://URL/web/content/<attachment_id>
Yes, You can use image by URL as below
http://serverurl/web/image/<odoomodelname>/<record_id>/<image_field_name>

How to create BufferedImage from bitmap data

After going through many similar looking questions I had no way but put my own question here.
I need to display an image on swing application. The source of image is bitmap data which is retrieved from MS SQL server. I have tried the following ways
TRY 1 - I have tried creating an ImageIcon from the bytes retrieved. No results.
TRY 2 - Saved the bytes in a .png file and tried loading Using ImageIO. This works fine on my local machine but fails on test server. Both are windows machines.
TRY3 - On step 2 I tried saving in different formats than .png. It does not work at all.
Please let me know what am I missing?
NOTE : I have tried including jai jars into the Referenced Libraries also.
You should have stored a hint what format the data has in the database. If not, you can only hope that ImageIO can handle it.
There is no need to write the data to files (which is a pitfall in itself, where would you write them? Think of restricted process privileges and disk quotas). Just create an InputStream that accesses the data directly (e.g. java.io.ByteArrayInputStream), that way you can have ImageIO load directly using the stream based methods.

java library to create, convert or edit images

I have to create thumbnails with images uploaded by my users. The image formats can be PNG, JPG, GIF. I gave a try to java.awt and javax.imageio but it is hard to deal with all the cases (image too large, image too small, image in XXX format, image with transparency...). I would prefer a library simple and not so verbose.
What java library do you use to convert / edit / create images ?
you might like to explore JMagick
Well, we use ImageIO and Apache Sanselan, but JAI or - if you don't mind using native libaries - jmagick should do as well.
image too large, image too small, image in XXX format, image with transparency
I'm not sure there is a library that doesn't have constraints like that. Since the images might be PNG, JPG or GIF, the format problem shouldn't apply.
Transparency is format dependent and thus should not depend on the library.
I chose Scalr, not need for extra ImageMagick or JNI wrapper :
http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/
On the other hand, quality is better with JMagick (if you can compile it and make it work)
Snowbound has the RasterMaster Java Imaging SDK. There is a decompress_bitmap call that will read in PNG, JPG, GIF and many other formats. The IMG_resize_bitmap_bicubic method can then be used to make a nice thumbnail.
You can go to Snowbound and push the "free trial" button to get a 30-day free trial version. The SDK comes with a Thumbnails code sample. If you want to learn more about the methods above before you expose your email address you can view the online documentation at RasterMaster.com.
Full disclosure - yes, I work for Snowbound.

Extracting image pixel values in google appengine

I am working on google appengine to create a tool for comparing image similarity.
I need to extract the pixel values of each image to perform this.
Unfortunately appengine does not support the java image libs.So I am unable to proceed.
Is there any appengine safe image library in java capable of extracting image data?
I saw some techniques in python but dont want to switch to python if I can do it in java somehow...
GAEJ has its own graphic library with fairly limited features and java.awt.image.BufferedImage is a restricted class (ie, java.awt.Image is not supported and still not present in the Jre Class White List ).
There's an open issue here, that you might want to star.
EDIT:
Somebody has patched pngj to work with InputStream.(You could use it to read a PNG pixel by pixel)
The new version of pngj now an alternative pngj-sandbox.jar that only references whitelisted classes, it should run in google-app-engine.
can https://github.com/witwall/appengine-awt help to you? i believe it willbe enough to add theis lib as dependency to the project to make BufferedImage working (but havent' tried this yet)

Categories