public Bitmap getScreenShotBitmap() {
//Drawable d = null;
DataInputStream dStream = null;
byte[] piex = null;
int[] colors = null;
int screenWidth = 0;
int screenHeight = 0;
int deepth = 0;
DisplayMetrics dm = null;
try {
dm = new DisplayMetrics();
WindowManager WM = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
Display display = WM.getDefaultDisplay();
display.getMetrics(dm);
screenWidth = dm.widthPixels; // Screen width (in pixels, such as: 480px)
screenHeight = dm.heightPixels; // Screen height (pixels, such as: 800p)
//Log.i(TAG, "screenWidth=" + screenWidth);
//Log.i(TAG, "screenHeight=" + screenHeight);
int pixelformat = display.getPixelFormat();
PixelFormat localPixelFormat1 = new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
deepth = localPixelFormat1.bytesPerPixel;//Bit depth
//Log.i(TAG, "deepth=" + deepth);
piex = new byte[screenHeight * screenWidth * deepth];//Pixels
colors = new int[screenHeight * screenWidth];
} catch (Exception e) {
Log.e(TAG, "Exception error", e);
}
FileInputStream buf = null;
File fbFile = null;
try {
fbFile = new File("/dev/graphics/fb0");
buf = new FileInputStream(fbFile);// Read the file contents
Log.i(TAG, "buf.toString()=" + buf.toString());
dStream = new DataInputStream(buf);
dStream.readFully(piex);
dStream.close();
// The rgb color values into
Log.i(TAG, "piex.length=" + piex.length);
/*for (int i = 0; i < piex.length; i += deepth) {
colors[i / deepth] = (int) 0xff000000
+ (int) (((piex[i + 1]) << (16)) & 0x00f80000)
+ (int) (((piex[i + 1]) << 13) & 0x0000e000)
+ (int) (((piex[i]) << 5) & 0x00001A00)
+ (int) (((piex[i]) << 3) & 0x000000f8);
}*/
for (int m = 0; m < colors.length; m++)
{
int b = (piex[m * 4] & 0xFF);
int g = (piex[m * 4 + 1] & 0xFF);
int r = (piex[m * 4 + 2] & 0xFF);
int a = (piex[m * 4 + 3] & 0xFF);
colors[m] = (a << 24) + (r << 16) + (g << 8) + b;
}
// Get screen bitmap
/*Bitmap bmp = Bitmap.createBitmap(colors, screenWidth, screenHeight,
Bitmap.Config.RGB_565);*/
// piex generate Bitmap
Bitmap bmp = Bitmap.createBitmap(colors, screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
//Log.i(TAG, "dm.densityDpi=" + dm.densityDpi);
//bmp.setDensity(dm.densityDpi);
return bmp;
/*
if(bmp != null){
d = dimManager.convertBitmapToDrawable(bmp);
}
return d;
*/
} catch (FileNotFoundException e) {
Log.e(TAG, "FileNotFoundException error", e);
} catch (IOException e) {
Log.e(TAG, "IOException error", e);
} catch (Exception e) {
Log.e(TAG, "Exception error", e);
} finally {
if (buf != null) {
try {
buf.close();
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Log.e(TAG, "finally IOException error", e);
}
}
}
return null;
}
//Drawable d = null;
DataInputStream dStream = null;
byte[] piex = null;
int[] colors = null;
int screenWidth = 0;
int screenHeight = 0;
int deepth = 0;
DisplayMetrics dm = null;
try {
dm = new DisplayMetrics();
WindowManager WM = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
Display display = WM.getDefaultDisplay();
display.getMetrics(dm);
screenWidth = dm.widthPixels; // Screen width (in pixels, such as: 480px)
screenHeight = dm.heightPixels; // Screen height (pixels, such as: 800p)
//Log.i(TAG, "screenWidth=" + screenWidth);
//Log.i(TAG, "screenHeight=" + screenHeight);
int pixelformat = display.getPixelFormat();
PixelFormat localPixelFormat1 = new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
deepth = localPixelFormat1.bytesPerPixel;//Bit depth
//Log.i(TAG, "deepth=" + deepth);
piex = new byte[screenHeight * screenWidth * deepth];//Pixels
colors = new int[screenHeight * screenWidth];
} catch (Exception e) {
Log.e(TAG, "Exception error", e);
}
FileInputStream buf = null;
File fbFile = null;
try {
fbFile = new File("/dev/graphics/fb0");
buf = new FileInputStream(fbFile);// Read the file contents
Log.i(TAG, "buf.toString()=" + buf.toString());
dStream = new DataInputStream(buf);
dStream.readFully(piex);
dStream.close();
// The rgb color values into
Log.i(TAG, "piex.length=" + piex.length);
/*for (int i = 0; i < piex.length; i += deepth) {
colors[i / deepth] = (int) 0xff000000
+ (int) (((piex[i + 1]) << (16)) & 0x00f80000)
+ (int) (((piex[i + 1]) << 13) & 0x0000e000)
+ (int) (((piex[i]) << 5) & 0x00001A00)
+ (int) (((piex[i]) << 3) & 0x000000f8);
}*/
for (int m = 0; m < colors.length; m++)
{
int b = (piex[m * 4] & 0xFF);
int g = (piex[m * 4 + 1] & 0xFF);
int r = (piex[m * 4 + 2] & 0xFF);
int a = (piex[m * 4 + 3] & 0xFF);
colors[m] = (a << 24) + (r << 16) + (g << 8) + b;
}
// Get screen bitmap
/*Bitmap bmp = Bitmap.createBitmap(colors, screenWidth, screenHeight,
Bitmap.Config.RGB_565);*/
// piex generate Bitmap
Bitmap bmp = Bitmap.createBitmap(colors, screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
//Log.i(TAG, "dm.densityDpi=" + dm.densityDpi);
//bmp.setDensity(dm.densityDpi);
return bmp;
/*
if(bmp != null){
d = dimManager.convertBitmapToDrawable(bmp);
}
return d;
*/
} catch (FileNotFoundException e) {
Log.e(TAG, "FileNotFoundException error", e);
} catch (IOException e) {
Log.e(TAG, "IOException error", e);
} catch (Exception e) {
Log.e(TAG, "Exception error", e);
} finally {
if (buf != null) {
try {
buf.close();
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Log.e(TAG, "finally IOException error", e);
}
}
}
return null;
}