Recently i had create a thumbnail from a video recorded in an Android Phone. I found out an easy way to create thumbnail using the ThumbNailUtils class.
Code for creating a thumbnail of a Video and saving it in a folder named "online" in the sdcard, in Android:
Code for creating a thumbnail of a Video and saving it in a folder named "online" in the sdcard, in Android:
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/online";
File mediaFile = new File(path);
if(!mediaFile.exists()){
mediaFile.mkdir();
}
File file = new File(mediaFile, "/IMG_"+timeStamp+".PNG".toString());
Bitmap thumbnail1 = ThumbnailUtils.createVideoThumbnail( selectedvideopath,MediaStore.Video.Thumbnails.MINI_KIND );
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
thumbnail1.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
String fileimg=file.getAbsolutePath().toString();
//fileimg has the path of thethubnail created
ByteArrayOutputStream baos = new ByteArrayOutputStream();
thumbnail1.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes,Base64.DEFAULT);
//encrypting the image using Base 64.
I hope this post was useful for you.....
Comments
Post a Comment