How to get thumbnail of video file in android - android

I have a video file in my sdcard. I would like to show a preview of this video in my ImageView . I know that there is a API:
ThumbnailUtils.createVideoThumbnail(videoFile,
MediaStore.Images.Thumbnails.MINI_KIND)
but it always returns null, is there any alternative?

Its working for me
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.MINI_KIND);
please check once, if you are passing path of video file .

MediaStore.Images.Thumbnails.MINI_KIND and MediaStore.Video.Thumbnails.MINI_KIND are both integers with value 1
So try this first
Bitmap bmp = ThumbnailUtils.createVideoThumbnail(videoPath,1);

Related

How to retrieve the video thumbnail in Android

My sdcard video folder contains number of .mp4 video files.
According to my requirement I want to list down those video files in my android application listview with their "Thumbnail" and "Name". BTW I plan to use Picasso or Universal image loader for image caching. Please tell me anyone know how to do?
import android.provider.MediaStore.Video.Thumbnails;
You can get two preview thumbnail sizes from the video:
Thumbnails.MICRO_KIND for 96 x 96
Thumbnails.MINI_KIND for 512 x 384 px
use this code
String filePath = "/sdcard/DCIM/Camera/my_video.mp4"; //change the location of your file!
ImageView imageview_mini = (ImageView)findViewById(R.id.thumbnail_mini);
ImageView imageview_micro = (ImageView)findViewById(R.id.thumbnail_micro);
Bitmap bmThumbnail;
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);
imageview_mini.setImageBitmap(bmThumbnail);
Check this link

Using frame by frame animation with Universal Image Loader

Is there any good way to use frame by frame animation AnimationDrawable using UIL library. AnimationDrawable accept only BitmpaDrawable . Is there any way to convert quickly to bitmaps my images or any maybe there is method like imageLoader.getBitmap, I haven't find anything like that.
Please help , I would be very grateful for any help .
Edit I have my images in assets folder. Maybe there any way to get bitmap from cache or something else . I need open new activity , maybe several times . I need to show animation from files , but if I use decode it takes a lot of time to decode them . Please suggest something
If your images are resources you can use this for obtain Bitmap:
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_resource);
else, if you want donwload the image you can use this:
String name = c.getString(url);
URL urlAux = new URL(name);
ImageView prueba = (ImageView)v.findViewById(R.id.iv_prueba);
if (prueba != null) {
Bitmap bitmap =
BitmapFactory.decodeStream(urlAux.openConnection().getInputStream());
prueba.setImageBitmap(bitmap);
}
Hope it helps you.

Set wallpaper from external storage

So I've got my image gallery project all set up with images saved online and not within the application. It works great. But what I want to do is get the facility to set the image as a wallpaper.
I've got the image to download and save in the external storage as packagename.jpg
Everywhere I've searched for examples on how to set the wallpaper all seem to be based on the image being within the application.
Anyone have any pointers on how to use wallpapermanger to set an image from external storage as the wallpaper?
You need to first retrieve the file from the SDCard and decode the image into a Bitmap using BitmapFactory then you can set the bitmap using WallpaperManager's setBitmap() method.
File file = new File(Environment.getExternalStorageDirectory(), "/directory/yourimage.jpg");
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getBaseContext());
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
wallpaperManager.setBitmap(myBitmap);

Android: I created a bitmap from canvas and save it to "sdcard/folder/subfolder" but I couldn't decode it to a image view

I've created a bitmap from canvas. Save it to my "/sdcard/folder/subfolder/file.png"
I want to get this png file into imageview after saving it. I tried this by using BitmapFactory.decodeFile("/sdcard/folder/subfolder/file.png"); method. But it returned nothing. There is no image on imageview.
Do you have any idea?
Try using
String filePath = Environment.getExternalStorageDirectory()+"/folder/subfolder/file.png";//or "folder/subfolder.."

How to load an ImageView from a png file?

I take a picture with the camera using
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult( intent, 22 );
When the activity completes, I write the bitmap picture out to a PNG file.
java.io.FileOutputStream out = openFileOutput("myfile.png", Context.MODE_PRIVATE);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
That goes OK, and I can see the file is created in my app private data space.
I'm having difficulty when I later want to display that image using an ImageView.
Can anyone suggest code to do this?
If I try to create a File with path separators in, it fails.
If I try to create a Uri from a name without separators, that fails.
I can open the file OK using:
java.io.FileInputStream in = openFileInput("myfile.png");
But that doesn't give me the Uri I need to set an image with
iv.setImageURI(u)
Summary: I have the picture in a png file in private app data. What's the code to set that into an ImageView?
Thanks.
Try BitmapFactory.decodeFile() and then setImageBitmap() on the ImageView.
Also possible:
java.io.FileInputStream in = openFileInput("myfile.png");
iv.setImageBitmap(BitmapFactory.decodeStream(in));
iv.setImageURI(Uri.fromFile(in));
Why not this way:
ImageView MyImageView = (ImageView)findViewById(R.id.imageView1);
Drawable d = Drawable.createFromPath( PATH TO FILE );
MyImageView.setImageDrawable(d);
bitmap = BitmapFactory.decodeFile(imageInSD);
There should be no difference between decodeStream() and decodeFile(). decodeFile() method opens an inputstream and calls decodeStream(). This was already answered at this link

Categories

Resources