//将Layout转化为Bitmap 用于保存
public static Bitmap saveViewPic(FrameLayout view) {view.setDrawingCacheEnabled(true);
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth() ,view.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());=
view.setDrawingCacheEnabled(false);
return bitmap ;
}
//将View转化为String用于保存
public static String saveViewPic(View view) {
view.setDrawingCacheEnabled(true);
Bitmap bitmap =view.getDrawingCache().copy(Config.RGB_565, false);
String string = uploadImage(bitmap);
Log.i("--------------", bitmap.getWidth() +"======="+bitmap.getHeight());
view.setDrawingCacheEnabled(false);
return string;
}
//将Layout转化为String用于保存
public static String saveViewPic(FrameLayout view) {
view.setDrawingCacheEnabled(true);
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth() ,view.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
// Bitmap bitmap =view.getDrawingCache().copy(Config.RGB_565, false);
String string = uploadImage(bitmap);
Log.i("--------------", bitmap.getWidth() +"======="+bitmap.getHeight());
view.setDrawingCacheEnabled(false);
return string;
}
private static String photo;
public static String uploadImage(Bitmap bmp ) {
// TODO Auto-generated constructor stub
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG,40, out);
out.flush();
out.close();
byte[] buffer = out.toByteArray();
byte[] encode = Base64.encode(buffer, Base64.DEFAULT);
photo = new String(encode);
// bmp.recycle();
// return photo;
// params.put("photo", photo);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return photo;
}