Skip to main content

How to create a thumbnail from a video in Android

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:



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

Popular posts from this blog

Server communication in Android

In Android we can communicate with server using HTTP request methods for getting some details from the server.We use RESTful service.Mainly we use two types of HTTP request HTTP GET(),HTTP POST() methods. In some case we have to give some values to the server for fetching some informations, then we use commonly HTTP POST() and if we simply want to request for some datas we use HTTP GET(). Lets see HTTP POST() method. public void getResponse(String a, String b) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("URL"); //here write the url List < NameValuePair > nameValueList = new ArrayList < NameValuePair > (2); nameValueList.add(new BasicNameValuePair("keyword", a)); nameValueList.add(new BasicNameValuePair("keyword", b)); try { httppost.setEntity(new UrlEncodedFormEntity(nameValueList)); HttpResponse response = httpclient.execute(httppost); Log.i(...

How to use Preference Activity in Android

Preference Activity is a base class mainly used for setting order of preferences of an user.It is mainly used for creating setting page of an user.In this example I am just showing how to set Preferences. First create an Activity MainActivity.java Here on clicking preference example button a page will be opened to set the preferences. On clicking the show values we can see the see the values that we have set. MainActivity.java import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.btn_pref); Button btn1 = (Button) findViewById(R.id.btn_values); btn.setOnCli...

Drag and drop image in android

Ever wonder how to drag and drop in android. Lets check how to drag and drop image in android. MainActivity.java package com.example.dragdrop; import android.app.Activity; import android.content.ClipData; import android.content.ClipDescription; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.os.Bundle; import android.util.Log; import android.view.DragEvent; import android.view.MotionEvent; import android.view.View; import android.view.View.DragShadowBuilder; import android.view.View.OnClickListener; import android.view.View.OnDragListener; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.SeekBar; import android.widget.ImageView.ScaleType; import android.widget.RelativeLayout; import android.widget.SeekBar.OnSeekBarChangeListener; public class MainActivity extends Activity { ImageView img_model, img_chain; private static final String IMAGEVI...