Android how to create runtime thumbnail
My Solution
byte[] imageData = null;
try
{
final int THUMBNAIL_SIZE = 64;
FileInputStream fis = new FileInputStream(fileName);
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
}
catch(Exception ex) {
}
Create dynamic thumbnail image from drawable resource and set to imageView
You need to change two things here :
1) BitmapFactory.decodeFile(categoryImagesList[position]), 100, 100)
to BitmapFactory.decodeResource(getResources(),categoryImagesList[position]);
2) Change holder.iv.setImageResource(thumbImage);
to holder.iv.setImageBitmap(thumbImage);
Android: Is it possible to display video thumbnails?
If you are using API 2.0 or newer this will work.
int id = **"The Video's ID"**
ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);
how can I show a video thumbnail from a video path?
It is the default way to create a thumbnail.
For Mini Kind
Bitmap thumb;
//MINI_KIND, size: 512 x 384 thumbnail
thumb = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
img_tumbnail.setImageBitmap(thumb);
For Micro Kind
Bitmap thumb;
//MICRO_KIND, size: 96 x 96 thumbnail
thumb= ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND);
img_tumbnail.setImageBitmap(thumb);
Also, you can use Glide for Url as well as Video path of Device.
Glide.with(context).with(this)
.asBitmap()
.load(videoFilePath) // or URI/path
.into(imgView); //imageview to set thumbnail to
also, you can resize thumbnail by using .override(50,50)
with Glide.
Android createVideoThumbnail returning null, but throwing Runtime Exception internally
You can use Glide to retrieve Thumbnail of Video.
// 1st: Generate image and set to imageview
Glide.with(context).asBitmap()
.load(filePathWithExtension)
.into(imageview);
// 2nd: Get Bitmap from Glide
GlideApp.with(context)
.asBitmap()
.load(filePathWithExtension)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
// You can use **resource**.
imageview.setImageBitmap(resource);
}
});
Related Topics
Check Whether Activity Is Active
Does the Web View on Android Support Ssl
Run Code Only Once After an Application Is Installed on Android Device
How to Get Retrofit Success Response Status Codes
How to Fix: "You Need to Use a Theme.Appcompat Theme (Or Descendant) with This Activity"
How to Send File Using Bluetooth on Android Programatically
How to Handle Ontouch Event for Map in Google Map API V2
Android: Disable Soft Keyboard at All Edittexts
Android - How to Enable Autostart Option Programmatically in Xiaomi Devices
How to Send JSON Object to Server Using Volley in Android
How to Store SQLite Database Directly on Sdcard
Android Exception: Did You Forget to Call 'Public Void Setup (Localactivitymanager Activitygroup)'
Error:Cause: Unable to Find Valid Certification Path to Requested Target
How to Resolve Java.Util.Zip.Zipexception
Listfragment Onlistitemclick Not Being Called
Customize Check Box Preference