I am generating a set of images on server. I need to encode and stream these real time to a android mobile, what is the best way possible, best encoder server side to do this?
Well, you can just have picutres stored in any format and just download them into device one by one. Only matters are how fast connection do you have, how many pictures do you want to send and how fast whole operation has to be finished.
Images downloaded from server in that way are stored in inputstream, which can be saved into file or used to create Bitmap with BitmapFactory and displayed within application. Be aware of OutOfMemoryError, which occurs while creating big resolution Bitmaps with BitmapFactory, as heap is shared amog all applications and is limited to 16 MB.
As for downloading process you can do that with HttpClient library available in Android.
Related
When I upload an image from a mobile device you have two options:
reduce the size on the device and upload the result
upload the full image and reduce the size on the server
Which one is better?
For the user experience, it is better to do all the work you can server-side, minimising the processing time and the transfer time.
I would recommend doing all the work on image on the server if you want the application to be fast, and if the transformation make the image heavier.
Now you may have problem in the future if you have mutliple upload in the same time with a low performance server. If it is the case, choose to do the work on device to devide the work on each device.
I think The "1" is best,because This way of consuming less flow;this option is very important for android app
I always use the 1st approach. You never know how fast your user's internet is, so I prefer doing it locally and save time on the upload.
That is specially true in 3d world countries where 3G speeds are generally very slow and unreliable.
I built an app that take pictures and upload them to THe server, i'm using Apache commons FTP library to upload them.
when i'm using wifi the images are uploaded without any issues...
but when i'm using 2G mobile network to send them half of them the server recieve them as corrupted images.
i set the file type to binary file type.
is there a way to determine whether the images got corrupted or not.
In order to determine whether the images got corrupted or not, compare the images received by the server with the corresponding ones on your Android device.
In order to determine why the images got corrupted, you may run WireShark or tcpdump on the server and snoop an upload. Careful examination should reveal if the problem is
within the server software (you see the complete image in the network traces), or
in the device or the network (you see a broken image in the network traces).
You also may experiment with image sizes (in terms of bytes) and check if there is a size boundary from which on you see problems. That might give clues on where to look further
Can you please suggest me the efficient encoding technique to transfer image from iphone/android to server.
base64 encoding is too easy but i've heard it is not recommended because it increases the size of original image upto 37%
Should I use base64 encoding,, UTF-8 encoding or read and write streams to send image to server?
i want to use it in image sharing application which is client server app, and client will upload their images to server.
Can you also tell me other possible techniques just for knowledge? and which one to use?
When it comes to phones especially Android streaming will be your best choice.
It's not matter what format you will choose base64 or UTF-8, eventually a stream will be opened in behind the scene.
The only thing that matters is RAM space consume by your application, if your client will try to encode it by him self before sending it, you will use more memory and some of the devices will run out of memory, this is much more impotent then the time it takes to upload the image to the server or the disc space used by server.
So my advice is: Do not manipulate the image, just stream it as-is, with the most common system tool your client can find.
I'm developing a small social networking app that makes use of something like profile pictures. Images are stored on a server and I have scripts set up that will send the image for each user to the app, which then displays it in an image view for each user, and then saves the image to external storage. The way I have it implemented now is that anytime the app needs the image after it downloads it from the server, the app will get the image from external storage unless a user has uploaded a new image (I thought this would be faster than redownloading it from the server every time). However, it seems to be taking longer to get the file from external storage than it does to get it from my server (and the server is pretty slow, running on wifi from 3 floors away...budget constrains :) ).
My question is what is the fastest way to get these images if the user hasn't uploaded a new one. Should I just downlaod it from the server everytime (I'm assuming not) or is there a better place in the filesystem to store the images that makes for faster retrieval?
Loading images from the SD card should be very fast. Some strategies:
Do it only once - Load the images into memory asynchronously when your activity or application starts. You don't want to be hitting the SD card every time your view updates.
Make them small - If you're having performance problems displaying thumbnails in a list, try saving your thumbnails as smaller images using inSampleSize to put less pressure on the decoder.
Use internal memory - I think that internal memory is faster, but it tends to be in short supply. You could certainly store some number of thumbnails in your cache directory to help speed up step 1.
Responsiveness over performance - The golden rule is to remember that absolute performance does not always correlate with responsiveness. Even if the images take a long time to load, choosing cleverly when to load the images can have a great impact on the user's perception of speed.
I am trying to display an image sent over a local network to my android device. An image is sent from a computer via tcp to my android device. The image is a png. The data sent over is a byte array stream of the png, which is packaged into a google protobuf message. On the android side, when receiving the data, it is read into a byte array, and the array is then given to BitmapFactory.decodeByteArray(). However, this returns null roughly 90% of the time. This only happens on a real device, but I can only test on the htc incredible at the moment. I've tried this on the android sdk emulator and i can get my image 100% of the time.
Other issues relating to BitmapFactory online has always been related to using file streams, where decoding isn't getting the entirety of the data, but I have yet to find any solutions for when the developer is sure the entirety of the data is received, and it only happens on a real device.
Is there some type of usage that I am unaware of for decodeByteArray()? The byte[] I am passing in is just the file itself.
Edit: Resolved thanks to a second insight from Brian Cooley.
I was just too quick to judge that the error may be in decodeByteArray(). If anyone ever runs into this problem do make sure that you make sure you have the data in its entirety. I made the false assumption that my byte stream was good. So first do a quick diff of the data you're sending and receiving, and make sure you're getting what you should.
One thing you might try is writing the raw bytes to a file on the SD card and looking at it on your computer, like was suggested for this question
This would reveal whether the problem is in the file or in your code. Since you are not seeing the problem in the emulator, my guess is that it is related to downloading the data over the phone.