android 截图scrollview
来源:互联网 发布:matlab退火算法 编辑:程序博客网 时间:2024/05/15 12:58
import android.graphics.Bitmap;import android.graphics.Canvas;import android.view.View;import android.widget.ListView;import android.widget.ScrollView;/** * 截图返回bitmap */public class SurfaceControl {public static Bitmap screenshot(View view) {view.setDrawingCacheEnabled(true);view.buildDrawingCache();Bitmap bmp = view.getDrawingCache();return bmp;}public static Bitmap screenshot(View view, int edgeLength) {view.setDrawingCacheEnabled(true);view.buildDrawingCache();Bitmap bmp = view.getDrawingCache();Bitmap result = centerSquareScaleBitmap(bmp, edgeLength);return result;}/** * 截取scrollview的屏幕 **/public static Bitmap getBitmapByScrollView(ScrollView scrollView) {int h = 0;Bitmap bitmap = null;// 获取listView实际高度for (int i = 0; i < scrollView.getChildCount(); i++) {h += scrollView.getChildAt(i).getHeight();//scrollView.getChildAt(i).setBackgroundResource(R.drawable.bg3);}// 创建对应大小的bitmapbitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888);final Canvas canvas = new Canvas(bitmap);scrollView.draw(canvas);// 测试输出//FileOutputStream out = null;//try {//out = new FileOutputStream("/sdcard/screen_test.png");//} catch (FileNotFoundException e) {//e.printStackTrace();//}//try {//if (null != out) {//bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);//out.flush();//out.close();//}//} catch (IOException e) {//// TODO: handle exception//}return bitmap;}/** * 截图listview * **/ public static Bitmap getbBitmap(ListView listView) { int h = 0; Bitmap bitmap = null; // 获取listView实际高度 for (int i = 0; i < listView.getChildCount(); i++) { h += listView.getChildAt(i).getHeight(); }// Log.d(TAG, "实际高度:" + h);// Log.d(TAG, "list 高度:" + listView.getHeight()); // 创建对应大小的bitmap bitmap = Bitmap.createBitmap(listView.getWidth(), h, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); listView.draw(canvas); // 测试输出// FileOutputStream out = null;// try {// out = new FileOutputStream("/sdcard/screen_test.png");// } catch (FileNotFoundException e) {// e.printStackTrace();// }// try {// if (null != out) {// bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);// out.flush();// out.close();// }// } catch (IOException e) {// // TODO: handle exception// } return bitmap; }/** * * @param bitmap * 原图 * @param edgeLength * 希望得到的正方形部分的边长 * @return 缩放截取正中部分后的位图。 */public static Bitmap centerSquareScaleBitmap(Bitmap bitmap, int edgeLength) {if (null == bitmap || edgeLength <= 0) {return null;}Bitmap result = bitmap;int widthOrg = bitmap.getWidth();int heightOrg = bitmap.getHeight();if (widthOrg > edgeLength && heightOrg > edgeLength) {// 压缩到一个最小长度是edgeLength的bitmapint longerEdge = (int) (edgeLength * Math.max(widthOrg, heightOrg) / Math.min(widthOrg, heightOrg));int scaledWidth = widthOrg > heightOrg ? longerEdge : edgeLength;int scaledHeight = widthOrg > heightOrg ? edgeLength : longerEdge;Bitmap scaledBitmap;try {scaledBitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, true);} catch (Exception e) {return null;}// 从图中截取正中间的正方形部分。int xTopLeft = (scaledWidth - edgeLength) / 2;int yTopLeft = (scaledHeight - edgeLength) / 2;try {result = Bitmap.createBitmap(scaledBitmap, xTopLeft, yTopLeft, edgeLength, edgeLength);scaledBitmap.recycle();} catch (Exception e) {return null;}}return result;}}
0 0
- android scrollview截图
- android 截图scrollview
- Android 普通View截图 RecyclerView截图 ScrollView截图分享
- android 长布局截图(listView ScrollView)
- 屏幕截图,view,ScrollView截图
- Android给scrollView截图超过屏幕大小形成长图
- Android给scrollView截图超过屏幕大小形成长图
- Android ScrollView截图和图片保存到相册的方式
- Android给scrollView截图超过屏幕大小形成长图
- ScrollView 完整截图实现
- Scrollview 生成长截图
- Android截屏截图方法汇总(Activity、View、ScrollView、ListView、RecycleView、WebView截屏截图)
- Android截屏截图方法汇总(Activity、View、ScrollView、ListView、RecycleView、WebView截屏截图)
- swift 高清截图 ScrollView截图
- Android截屏截图方法所有方法汇总(包括Activity、View、ScrollView、ListView、RecycleView、WebView截屏截图)
- Android截图
- android 截图
- Android截图
- Java数组-数组的应用-应用查表法将十进制整数转化为16进制-2
- 游戏服务器架构文档
- 在VS2013上搭建wxWidgets开发环境
- 大型网站技术架构(一):架构演变过程和架构体系
- 41.内核链表状态机多线程编译器
- android 截图scrollview
- i2c写操作收到nack后重发------24C02B/24C16N i2c写实例
- win10下apache服务的下载安装与配置
- 配置 mybatis的 log4j.properties
- 非select模式下的时间三级联动,
- Lucene使用单字分词及短语查询实现类似全模糊查询效果
- naoj 37 回文字符串
- 浅谈Android - BitmapShade 并用BitmapShade 实现一个圆形图片
- 零零碎碎的模拟题