Android how to load Image file with different extension using Picasso - android

This is a different situation. I want to load a image file which has stored with different extension like 'photo.xyz' instead of 'photo.jpg or photo.png' using Picasso. to avoid image from gallery i am storing image like this. Please help me is there any option to show like this.

Neither Picasso nor Android (which does the actual image decoding) cares what the file name is. It can be anything. The type of the image is always determined from the first few bytes of the actual image data.

As a small workaround you can programmatically put .nomedia file into your app folder to prevent images to be cached by mediaserver and displayed in a Gallery app.

Related

which is best? Creating bitmap from imageview or downloading the file

we are using an app for setting wallpaper in android device, for that we are doing below steps
1) we have set of images and URLs
2) We are fetching the URL on an Imageview
so now we have to set the wallpaper, for that we need the image file, which is the best way to do it?
1) Download the file directly from URL and store it in a local storage and use it as wallpaper.
or
2) Create a bitmap from the Imageview and use it as wallpaper.
Doing the second option will reduce any quality of the image we using?
First option how to we can do it?
We have fetch the images successfully inside the application.
Always prefer to cache your image downloads so that you don't have to repeat the task. Using libraries like Picasso or Glide reduces a lot of effort is handling your images while at the same time optimizing your code.
Additionally it's best to use the original image as wallpaper rather than consuming the image view because if you have set any scale type's on your image view then your image will be cropped.
Picasso allows for hassle-free image loading in your application—often in one line of code!
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

Android: Hardcode images with paths

I am working on an a simple android application that stores objects in an array, and displays them to the user via a listview. Each object contains a photo and a single text field. For demonstration purposes, I would like to pre-populate this array with some hardcoded objects.
The trouble is that the images are typically acquired through the camera interface, and each object only stores the path to that image. I can add the hardcoded images as drawables, but then they don't have a file path. I could when the app is initialized, convert the drawables to bitmaps and save the bitmaps to the SD card, but that seems too complicated to be the correct answer...
Any ideas on the best way to get these images into file storage so that I refer to them via their URIs?
Thanks!
When you create your views in your adapter, have a ImageView in your layout and use a loader or custom AsyncTask to load the image in the background and have it update the ImageView instance once it has the data.
check the background from this on loading images from the network.
You acquire images from the camera but notice that when you do a resource chooser where mimetype = img/*, the selector just merges local camera(gallery) storage with other photo, content providers. An example of common chooser for photos is in 'Evernote' where you go to the composer view with the 2X2 grid and touch the 'attachment' icon... thats a photo chooser...
In other words , it helps to understand the general practice for managing photos and for presenting them in imageViews.
Typically, there is a lazyLoader that has an interface with args for the imgView and the URI of the image source. Under the covers on a call to 'loadImage(view, uri), the implementation checks the following:
is the bitmap already in a memCache?
the local file , that backs the bitmap, does it exist in the folder reserved for this purpose?
if none of above, go get the array of bytes for the img from across the network ( or in your case , get bytes from camera ).
Even though your question is a little different , IMO , the standard practices for images may apply and you may want to adapt one of the many libs for image presentation to your specific requirements.

How take photo and reduce image file dimension

in my android app i've implemented a method for taking a photo and save it in a folder specified by me.
I would like to automatically resize the image (or compress it) to reduce the file dimension under the 1MB, obviously before saving it.
Which is the best way to do this?
Thanks
Take a look at this: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html , it has good examples of how to keep your filesize down on photos

how to display images from a selected folder in the form of a slideshow

I am using the following code to pick a folder from the SDCard.
Environment.getExternalStorageDirectory();
After selecting the folder, I return the path of the folder and display it in a text view currently.
What I want to do is, I want to display all images in the selected folder in the form of a slide show. How do I go about in doing this?
1. convert images in the Bitmap.
Bitmap bm = BitmapFactory.decodeFile(String pathName);
Decode a file path into a bitmap.BitmapFactory
2. Using ImageView set that Bitmap in ImageView.
ImageView.setImageBitmap(Bitmap bm);
Sets a Bitmap as the content of this ImageView.
3. For slide show just after some delay (use timer) after change the bitmap of ImageView.
We are appreciate If you are do by yourself. Without finding any code.
EDIT: Here Mihai Fonoage's Blog Displaying Images from SD Card In Android - Part 2 It display images from sdcard in Gridview. You can modified it and display Images one-by-one as a slideshow.
If all you want to do is cycle through the images one by one, there are numerous options. You could for example simply use a Timer (or preferably a ScheduledThreadPoolExecutor if you're writing production code) with a fixed interval or have a Handler repeatedly post itself with a certain delay. With each 'tick' you can then simply set the next image.
If you're after something a little more fancy, it may be worth looking at implementing an ImageSwitcher, which provides the ability to also show thumbs of upcoming/previous images. Code examples are wide spread, e.g. here (scroll down a bit).

What is the most efficient way to load my stored JPG file into the ImageView?

I have valid JPG files and now I want to load them into a layout containing an ImageView. I have code to findViewId(R.id.myimage). I followed some sample code using File but it did not work. The file is stored at /data/data/com.myapp/files/someimage.jpg.
What is the easiest and efficient way to load and display?
((ImageView)view).setImageBitmap(BitmapFactory.decodeFile("/data/data/com.myapp/files/someimage.jpg"));
With the few info you give that's all I can do.

Categories

Resources