html2canvas截取屏幕的方法
html2canvas截取屏幕的方法
需要放在服务上运行,否则会报错,

放在服务器里,完美运行
处理截屏模糊的方法
html2canvas 0.5.0-beta3解决截图模糊问题
需要引入html2canvas 0.5.0-beta3
var shareContent = $(".hbdiv");// 需要绘制的部分的 (原生)dom 对象 ,注意容器的宽度不要使用百分比,使用固定宽度,避免缩放问题
var width = shareContent[0].offsetWidth; // 获取宽度
var height = shareContent[0].clientHeight; // 获取高
var offsetTop = shareContent[0].offsetTop; //元素距离顶部的偏移量
var canvas = document.createElement('canvas'); //创建canvas 对象
var context = canvas.getContext('2d');
var scaleBy=10; //获取像素密度的方法 (也可以采用自定义缩放比例)
//var scaleBy=hqmd(context);
canvas.width = width * scaleBy; //这里 由于绘制的dom 为固定宽度,居中,所以没有偏移
canvas.height = (height + offsetTop) * scaleBy; // 注意高度问题,由于顶部有个距离所以要加上顶部的距离,解决图像高度偏移问题
context.scale(scaleBy, scaleBy);
var opts = {
scale:scaleBy, // 添加的scale 参数
canvas:canvas, //自定义 canvas
width:width, //dom 原始宽度
height:height //dom 原始高度
};
html2canvas($('.hbdiv'), opts).then(function (canvas) {
var strDataURI = canvas.toDataURL("image/jpeg");
$("body").html('');
$("body").append($("<img>").attr("class", 'bimg').attr("src", strDataURI));
});
获取像素密度方法
function hqmd(context){
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}
html2canvas截取屏幕的方法的更多相关文章
- jquery 截取屏幕
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- shell截取字符串的方法
参考文献: linux中shell截取字符串方法总结 [Linux]如何在Shell脚本中计算字符串长度? 截取字符串的方法一共有八种,主要为以下方法 shell中截取字符串的方法有很多中, ${ex ...
- paip.截取字符串byLastDot方法总结uapi python java php c# 总结
paip.截取字符串byLastDot方法总结uapi python java php c# 总结 ========uapi left_byLastDot right_byLastDot 目前 ...
- shell中截取字符串的方法总结
shell中截取字符串的方法有很多种, ${expression}一共有9种使用方法. ${parameter:-word} ${parameter:=word} ${parameter:?word} ...
- Android实例-程序界面内截取屏幕(XE8+小米2)
结果: 1.只能截取程序界面内的图片. 2.图片有点不清楚,自己设置清楚度. 实例代码: unit Unit1; interface uses System.SysUtils, System.Type ...
- c#中字符串截取使用的方法
AndyZhang welcome to java world c#中字符串截取使用的方法 String substring(int beginIndex) String substring(int ...
- cocos2d-x 截取屏幕可见区域
在游戏中,我们经常需要分享到社交网络的功能.分享时,我们时常会需要用到截屏的功能.目前网上的文章虽然很多,但是都是截取的 设计分辨率(DesignResolutionSize)大小的屏幕,而这个并不是 ...
- PHP截取中文字符串方法总结
<?php @header('Content-type: text/html; charset=UTF-8'); $arr = "sa撒的发dfa多少sfd看sdf得12上24飞452 ...
- java中把list列表转为arrayList以及arraylist数组截取的简单方法
java中把list列表转为arrayList以及arraylist数组截取的简单方法 package xiaobai; import java.util.ArrayList; import java ...
随机推荐
- Leetcode946. Validate Stack Sequences验证栈序列
给定 pushed 和 popped 两个序列,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop 操作序列的结果时,返回 true:否则,返回 false . 示例 1: 输入:pus ...
- Android 开发 Camera2开发_3_处理预览和拍照偏暗问题
通过调整曝光解决 参考:https://stackoverflow.com/questions/28429071/camera-preview-is-too-dark-in-low-light-and ...
- JZOJ2368 【SDOI2011】黑白棋
题目 题目大意 在一个1*n的棋盘上,有黑棋和白棋交错分布,每次,一个人可以移动自己的ddd颗旗子. 问先手必胜的方案数. 思考历程 在一开始,我就有点要放弃的念头. 因为这题是一道博弈问题. 我是非 ...
- LUOGU P2675 《瞿葩的数字游戏》T3-三角圣地
题面 解题思路 手推可以得出,最后每个数字的贡献其实就是第n行杨辉三角数,然后直接卢卡斯直接算(今天才找到lucas定理时间复杂度是log n,log以模数为底).代码略麻烦,不想改了. 代码 #in ...
- 使用MySQL会话变量实现窗口函数
一.MySQL窗口函数 (1) 序号函数 row_number()在相等的两条记录上随机排序,但序号按照1.2递增,然后后面的序号继续递增为3,中间不会产生序号间隙: rank()/dense_ran ...
- 知道了为什么osg::impostor可以这样设置geometry的QUADS了
之前一直不理解为什么osg::impostor里面的impostorSprite可以直接设置impostorSprite->getCoords()来设置geometry的四个边角,其实是因为这个 ...
- [Array]217.Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- memcache 拓展
需要安装Libevent.memcached.memcache. 参考网址:https://www.cnblogs.com/hejun695/p/5369610.html 启动:/usr/local/ ...
- Lowest Common Ancestor (LCA)
题目链接 In a rooted tree, the lowest common ancestor (or LCA for short) of two vertices u and v is defi ...
- datetime模块常用函数
import datetime import time # 当前时间戳 now = time.time() print(now) # 时间戳转换成时间元祖 now = time.localtime(n ...