get Screen Cap - Android android.app

Android examples for android.app:Screen

Description

get Screen Cap

Demo Code

import java.io.File;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.provider.MediaStore;

public class Main {

  public static Bitmap getScreenCap(File f, Activity activity) {
    String filePath = f.getAbsolutePath();
    String[] proj = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.DATA };
    Cursor cursor = activity.managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj,
        MediaStore.Video.Media.DISPLAY_NAME + "=?", new String[] { filePath }, null);
    cursor.moveToFirst();/*  w w w .ja v a  2 s  .  co  m*/
    long fileID = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 1;
    ContentResolver crThumb = activity.getContentResolver();
    Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, fileID, MediaStore.Video.Thumbnails.MICRO_KIND,
        options);

    return curThumb;
  }

  protected static Bitmap getThumbnail(File f) {
    Options thumbOptions = new Options();
    thumbOptions.inSampleSize = 8;

    return getImage(f, thumbOptions);
  }
  private static Bitmap getImage(File f, Options options) {
    Bitmap image = BitmapFactory.decodeFile(f.getAbsolutePath(),
            options);
    return image;
}
}

Related Tutorials