当前位置:   article > 正文

Layout(View)保存为Bitmap或者保存为String_gdspy-layout viewer如何保存

gdspy-layout viewer如何保存

//将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;
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/262114
推荐阅读
相关标签
  

闽ICP备14008679号