publicstaticBitmapgetViewBitmap(Viewv){
v.clearFocus();//
v.setPressed(false);//
//能画缓存就返回false
booleanwillNotCache=v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false);
intcolor=v.getDrawingCacheBackgroundColor();
v.setDrawingCacheBackgroundColor(0);
if(color!=0){
v.destroyDrawingCache();
}
v.buildDrawingCache();
BitmapcacheBitmap=v.getDrawingCache();
if(cacheBitmap==null){
//Log.e(TAG,"failedgetViewBitmap("+v+")",new
//RuntimeException());
returnnull;
}
Bitmapbitmap=Bitmap.createBitmap(cacheBitmap);
//Restoretheview
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
returnbitmap;
}
//保存到sdcard
//savePic(getViewBitmap(v),"sdcard/xx.png");
privatestaticvoidsavePic(Bitmapb,StringstrFileName){
FileOutputStreamfos=null;
try{
fos=newFileOutputStream(strFileName);
if(null!=fos){
b.compress(Bitmap.CompressFormat.PNG,90,fos);
fos.flush();
fos.close();
}
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
}
v.clearFocus();//
v.setPressed(false);//
//能画缓存就返回false
booleanwillNotCache=v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false);
intcolor=v.getDrawingCacheBackgroundColor();
v.setDrawingCacheBackgroundColor(0);
if(color!=0){
v.destroyDrawingCache();
}
v.buildDrawingCache();
BitmapcacheBitmap=v.getDrawingCache();
if(cacheBitmap==null){
//Log.e(TAG,"failedgetViewBitmap("+v+")",new
//RuntimeException());
returnnull;
}
Bitmapbitmap=Bitmap.createBitmap(cacheBitmap);
//Restoretheview
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
returnbitmap;
}
//保存到sdcard
//savePic(getViewBitmap(v),"sdcard/xx.png");
privatestaticvoidsavePic(Bitmapb,StringstrFileName){
FileOutputStreamfos=null;
try{
fos=newFileOutputStream(strFileName);
if(null!=fos){
b.compress(Bitmap.CompressFormat.PNG,90,fos);
fos.flush();
fos.close();
}
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
}