Last active
September 17, 2016 16:22
-
-
Save maicong/c3df539ec94017c3fb44b9300339bd3c to your computer and use it in GitHub Desktop.
获取base64格式的占位图片
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.createElement('canvas'); | |
var ctx = canvas.getContext('2d'); | |
canvas.width = 1; | |
canvas.height = 1; | |
ctx.fillStyle = '#f5f5f5'; | |
ctx.fillRect(0, 0, 1, 1); | |
console.log(canvas.toDataURL()); | |
// data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2P8+vXrfwAJpgPg8gE+iwAAAABJRU5ErkJggg== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment