直播视频网站源码,截图工具类

public class ScreenShotHelper {
    /**
     * 保存View的截图到文件
     *
     * @param bmp
     * @param path
     *            eg: "/mnt/sdcard/"
     * @param name
     *            eg: "abc.png"
     * @param quality
     *            质量等级 0~100
     * @return
     */
    public static boolean saveViewAsPNG(View v, String path, int quality) {
        boolean ret = false;
        v.setDrawingCacheEnabled(true);
        Bitmap bmp = v.getDrawingCache();
        if (bmp == null) { // 实在截取不到view就截全屏吧
            v.setDrawingCacheEnabled(false);
            v = v.getRootView();
            v.setDrawingCacheEnabled(true);
            bmp = v.getDrawingCache();
        }
        if (bmp != null) {
            FileOutputStream fOut = null;
            try {
                File f = new File(path);
                File dir = f.getParentFile();
                if (!dir.exists()) {
                    dir.mkdirs();
                }
                f.createNewFile();
                fOut = new FileOutputStream(f);
                bmp.compress(Bitmap.CompressFormat.PNG, quality, fOut);
                fOut.flush();
                ret = true;
            } catch (FileNotFoundException e) {
                // createNewFile failed
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (fOut != null) {
                    try {
                        fOut.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        v.setDrawingCacheEnabled(false);
        return ret;
    }
}

以上就是直播视频网站源码,截图工具类相关的代码, 更多内容欢迎关注之后的文章

上一篇:直播短视频源码,邻接矩阵实现图的相关代码


下一篇:PHP短视频源码,实现圆形波浪图