canvas

Canvas drawImage using data URL

徘徊边缘 提交于 2020-01-31 22:08:10
问题 I'll start with the script: function saveInstance() { _savedInstance = document.getElementById('canvasID').toDataURL(); } function restoreInstance() { ctx.drawImage(_savedInstance,0,0); } The purpose is to save an instance of the canvas and re-apply it later [Similar to how ctx.save() saves the style and transformations]. However, I got the error that says incompatible types (Uncaught Error: TYPE_MISMATCH_ERR: DOM Exception 17). Is there any canvas method that will allow me to use the data

Canvas drawImage using data URL

六眼飞鱼酱① 提交于 2020-01-31 22:07:51
问题 I'll start with the script: function saveInstance() { _savedInstance = document.getElementById('canvasID').toDataURL(); } function restoreInstance() { ctx.drawImage(_savedInstance,0,0); } The purpose is to save an instance of the canvas and re-apply it later [Similar to how ctx.save() saves the style and transformations]. However, I got the error that says incompatible types (Uncaught Error: TYPE_MISMATCH_ERR: DOM Exception 17). Is there any canvas method that will allow me to use the data

Write text on canvas with background

纵饮孤独 提交于 2020-01-31 21:58:47
问题 Is it possible to write image on canvas and write text with background? For example like this: 回答1: How text works in canvas Unfortunately no, you can't produce text with background with the text methods - only fill or outline the text itself. This is because the glyphs from the typeface (font) are converted to individual shapes or paths if you want, where the background of it would be the inner part of the glyph itself (the part you see when using fill). There is no layer for the black-box

Write text on canvas with background

橙三吉。 提交于 2020-01-31 21:57:06
问题 Is it possible to write image on canvas and write text with background? For example like this: 回答1: How text works in canvas Unfortunately no, you can't produce text with background with the text methods - only fill or outline the text itself. This is because the glyphs from the typeface (font) are converted to individual shapes or paths if you want, where the background of it would be the inner part of the glyph itself (the part you see when using fill). There is no layer for the black-box

HTML5- Canvas入门(六)

别来无恙 提交于 2020-01-31 09:36:00
已经第六章了,也差不多接近尾声,如果你从第一章耐心follow到本章结束,那你便能掌握canvas的大部分知识点(当然如果要精通,还是得多靠练习,做一些小案例)。 今天我们要学习的是canvas的变形转换方法。 缩放方法 scale() 在canvas中,如果我们需要缩放当前绘图对象,可以利用 scale() 来实现,其语法为 ctx.scale( s_width, s_height ); s_width 和 s_height 表示要缩放的宽度或高度的 缩放倍数 ,注意这两个参数的值不再是像素值而是缩放倍数,比如1表示不缩放、0.5表示缩小50%、2.3表示放大2.3倍。我们来个例子: <canvas id="myCanvas" width="400" height="350" style="border:solid 1px #CCC;"> 您的浏览器不支持canvas,建议使用最新版的Chrome </canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); var img = new Image(); img.src = "http://images.cnblogs.com/cnblogs_com/vajoy/558869/o_avatar.jpg";

HTML5 Canvas 颜色填充学习

点点圈 提交于 2020-01-30 15:29:42
---恢复内容开始--- 如果我们想要给图形上色,有两个重要的属性可以做到:fillStyle 和 strokeStyle。 fillStyle = color strokeStyle = color strokeStyle 是用于设置图形轮廓的颜色,而 fillStyle 用于设置填充颜色。color 可以是表示 CSS 颜色值的字符串,渐变对象或者图案对象。默认情况下,线条和填充颜色都是黑色(CSS 颜色值 #000000)。 下面的例子都表示同一种颜色。 ctx.fillStyle = "orange"; ctx.fillStyle = "#FFA500"; ctx.fillStyle = "rgb(255,165,0)"; ctx.fillStyle = "rgba(255,165,0,1)"; 注意: 目前 Gecko 引擎并没有提供对所有的 CSS 3 颜色值的支持。例如,hsl(100%,25%,0) 或者 rgb(0,100%,0) 都不可用。 注意: 一旦您设置了 strokeStyle 或者 fillStyle 的值,那么这个新值就会成为新绘制的图形的默认值。如果你要给每个图形上不同的颜色,你需要重新设置 fillStyle 或 strokeStyle 的值。 Canvas填充样式fillStyle 说明 在本示例里,我会再度用两层for循环来绘制方格阵列

Cannot save a Transparent PNG from my canvas in C#

我的梦境 提交于 2020-01-30 12:09:27
问题 I made a WPF canvas program which lets users add some PNG templates and make their own new design. I could complete the working However when I try to save , I get the white background Is there any way to get a transparent output ? This is my code on saving image public void SaveTo(string f) { Visual v = Dc; /// get bound of the visual Rect b = VisualTreeHelper.GetDescendantBounds(v); /// new a RenderTargetBitmap with actual size of c RenderTargetBitmap r = new RenderTargetBitmap( (int)b.Width

Chart.js Picture inside doughnut segment

你。 提交于 2020-01-30 10:56:09
问题 I found out about chart.js and I am looking to use a doughnut chart for my website, I found a example where I can take the basics from : https://jsfiddle.net/9wp4f693/2/ I've only found something like this, but it was to draw text inside the segments, not to add pictures. function drawSegmentValues() { for(var i=0; i<myDoughnutChart.segments.length; i++) { ctx.fillStyle="white"; var textSize = myChart.width/10; ctx.font= textSize+"px Verdana"; // Get needed variables var value =

Chart.js Picture inside doughnut segment

扶醉桌前 提交于 2020-01-30 10:56:07
问题 I found out about chart.js and I am looking to use a doughnut chart for my website, I found a example where I can take the basics from : https://jsfiddle.net/9wp4f693/2/ I've only found something like this, but it was to draw text inside the segments, not to add pictures. function drawSegmentValues() { for(var i=0; i<myDoughnutChart.segments.length; i++) { ctx.fillStyle="white"; var textSize = myChart.width/10; ctx.font= textSize+"px Verdana"; // Get needed variables var value =

Using OnKeyDown and OnPreviewKeyDown in a Canvas

会有一股神秘感。 提交于 2020-01-30 08:33:05
问题 I have a DragCanvas class that inherits from Canvas and that implements functionality in order to grab, drag and resize elements. The DragCanvas class is very similar to the one provided by Josh Smith in the following article: http://www.codeproject.com/Articles/15354/Dragging-Elements-in-a-Canvas I'd like to be able to capture keyboard events as well in order to delete elements and duplicate them. I have overriden the OnKeydown and OnPreviewKeyDown methods and placed breakpoints in there,