Which is Faster regarding Android Images IO - java

Which is faster, to recieve images as JPG from server, and save it, then show it in a ListView or what ever
OR
receive images in an XML (as encoded String) from server, then decode it, then show it in a ListView (or even save it then show it from memory)
what is the best way (regarding performance) in transfering images FROM a server TO an android device
thanks in advance

That depends on where the limitation is. If the bandwidth of your connection is very small try to transfer as few bytes as possible. However, high compression usually costs more CPU, so if CPU power is limiting you it may be better to use a lower compression.
I am not sure what you mean by "receive images in an XML". Is it some vector format like SVG? That would normally be much smaller than a raster image (especially for large sizes).
To sum up, you will need to do some experiments to find out what works best in your case.

The best way is to get the image URL from the server and then download the image using some image managing library like https://github.com/nostra13/Android-Universal-Image-Loader or google's volley. These kind of libraries highly configurable and taking care of all the aspects of managing a bitmap.

Related

Read Compressed images at runtime + Optimal image compression tool

As a challenge and practicality, I have a few images I want to include inside my jar for a mod I'm developing. But as is the compiled jar with the images ends up weighing over 25 MBs, which is not ideal. So my idea is to simply compress them and add that compressed package as a resource. But doing so doesn't appear to shrink the file size that much. So the two questions I want to ask (if that plan makes sense) what's the best way to compress a bunch of images and then being able to utilize them while running the game/program?
Lossy image compression is one way to reduce file size, but when dealing with images that cover the entire screen the drop in quality can easily be noticed, which is not what I want.
Another solution is to simply not have it part of the mod and instead needs to be downloaded individually and read from it. But that's a little cheap and still would have to download the same amount of MBs to get the full experience.
Note. I don't need to compress them in my program, just read from them when they are compressed.

How can I download scaled down version of an image?

I need to download images that are very large 5mb+.
I am aware of scaling the image before displaying it to save phone memory but the problem of downloading a large image still remains.
How can I download, say, a 50% scaled down version of an image rather than downloading a full image then scaling it?
It must be supported by the server from which you download.
If the server is not yours, you need to look up that server's documentation (or reverse-engineer).
If the server is yours, it depends on the used technology. Look up an image manipulation library for that particular server-side technology you are using.
in case of imgur.com,
look here: http://api.imgur.com/
Imgur lets you make 500 calls per hour per IP, or 1000 if you are registered. Uploads count tenfold.
The metadata about an image is documented here: http://api.imgur.com/resources_anon#image_hash . Access either api.imgur.com/2/image/[hash].xml or api.imgur.com/2/image/[hash].json, and pick either image.links.small_square (90x90) or image.links.large_thumbnail (?x640) from the response. Note that imgur also generates thumbnails (160x160) for its home page. URLs for these seem to be i.imgur.com/[hash]b.jpg
The link to the large image is i.imgur.com/[hash].jpg, so if your link is http://i.imgur.com/xDpEF.jpg or http://imgur.com/xDpEF, then xDpEF is the hash you need.
It is NOT possible to download a scaled down version of some image when the web server does not provide a scaled down version.
You'll need to scale them in the web/on the server, where you host them. So the question is not java/android, but on the webserver, and depends on it.
You can't, unless your server supports scaling down the image before you download it. If the server doesn't have that option, your best option is to scale it down while you read the image from the stream, using BitmapFactory.Options inSampleSize.
Sir it is impossible because if you are downloading it from any server then server must have the scaled image in many forms like 50% scale or 25% scaled. So it is possible only when the server is maintained by you from where you are downloading the image and at backend you have provided some method to scale the image.
If you are downloading the image from any server then is is not possible to get scaled image from server without any backend procedure to scale image.
You will need to download the image to a file, then use BitmapFactory with BitmapFactory.Options to determine the size of the image. From the image size, calculate how much you want to scale it, and again use BitmapFactory (with Options) to load a scaled version of the image.
It depends on Server, Server should support scaling down the image.
In addition to the other answers there is one solution that may work without special software on server side;
If the images are stored on the server in JPEG format and uses the interlaced / progressive mode you would be able to download them partially for creating a thumb nail.
This special mode was designed to see a preview-image while it is still downloading. Compacting the preview image could result in an image that can be used as a thumbnail.
However I don't know a library that would support thumbnail loading this way.

Fast lossless image compression in Android?

I need to save a series of large bitmaps to disk in Android in a lossless format. However, I've found that the built-in PNG encoder is quite slow e.g. it's taking about 8 seconds to save 3 large images when I need something that takes around 2 seconds. Are there any other lossless options for saving bitmaps in Android?
I'm happy to sacrifice a little disk space for speed. However, the compression level parameter for saving PNG images in Android is ignored for PNGs (by design). Perhaps there are some easy to use options that involve the NDK?
The slowness may depend on how (the approach) you are saving it..Did you try using AsyncTask?

java image compression and reduce bytes size

I developed a mass file up loader (a swing application) recently.One of the new requirements is to support uploading thousands of documents (GIF,JPG,PNG,DOCX,XLSX), each of these are like 3MB-10MB of size and we don't want to upload these huge files, we generally support TIFF files which has small byte size like 60KB-100KB. We are not concerned about the image quality, all we need to upload these docs for future reference. Right now I don't have any idea how to solve this problem, I started researching it. Please point me in right direction.
-PD
My first approach would be to convert them to pdf files. Everything that can be printed can be converted to pdf. This also allows for image compression. Tiff won't be a good idea for doc/xls I think, it might make them bigger.
a .doc or .xlsx can be gzipped very quickly for decent savings.
Images are more risky, depends on what the data is. Pictures of people? Pictures of text?

Java applet screen capture to a video

I wanted to find out how can one capture screencast using java. I know that using Robot class one can get a screenshot but how do I go about capturing it as a video and then uploading it to the server? How exactly would that work?
ideas?
With a pure Java solution, I doubt that it will work, but it depends of course on what your interpretation of "video".
On my desktop with a 1920x1200 resolution, I am able to get about 20 frames per second when using the Java Robot to capture the entire screen. Since each image contains >6 MByte of uncompressed data, I would need more than 1 Gbps bandwidth to transmit the raw data of these images to a server. Most probably, requiring so much bandwidth is not acceptable, so you either have to decrease the number of frames per second or apply some kind of compression to the images.
One possibility is to compress each image using one of the image formats supported by ImageIO. The size of the compressed images will of course depend heavily on what is actually shown on the screen, but the performance of the compressors is not particularly good. Compressing to PNG ought to give the best lossless compression ratio for most desktop content, but at least my computer is only able to process just about 2 frames per second. Using the JPEG compressor with default quality settings reaches about 5 frames per second.
Using common video codecs through an abstraction layer like jffmpeg will probably achieve both better performance and better compression ratio, but I doubt that mainstream video codecs like WMV or H.264 are suitable for common desktop content.
If you really require a pure Java solution (and are not able to use any of the available standalone software, which do what you're asking for), I would make an attempt to implement my own, simple compression algorithm. With common desktop activity, there ought to be very little difference between most consecutive screen shots, so what might work quite well is to transmit the first frame completely and after that implement an algorithm to roughly detect rectangles, in which changes have been made and then transmit only these combined with JPG or preferrably (quality) PNG compression.
Or use Xuggler, a better wrapper for FFmpeg in Java. In fact, the code for capturing the screen and encoding the video is one of the standard tutorials.
I'm also curious about this. https://www.screencast.com/ is currently doing just this with a pure java (or at least straight out of the browser) experience.
You can just use something like Java to a native FFMPEG build, and execute the command line at runtime. Here is an applet that I made that does just that: http://have2chat.net/screencast/
I have downloaded the main capture *.JAR file for the Screencast-O-Matic.com. To download the file:
Go to http://screencast-o-matic.com/jars/ScreencastOMaticRun-1.0.5.jar
Save the file
Extract the contents (I DO NOT intend to use this commercially!)

Categories

Resources