canvas

Rotate text in a canvas with javascript

三世轮回 提交于 2020-01-17 02:56:06
问题 In the following code i want to rotate the text of each element of the array in javascript. If i use for example ctx.rotate(Math.PI/10) before the filltext, it rotates all the elements. The positioning of the text also changes with ctx.rotate(Math.PI/10) and if i use 90 degrees, ctx.rotate(Math.PI/2) the text does not show on the canvas. <html> <canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;"></canvas> <script> var c = document.getElementById("myCanvas"); var

Rotate text in a canvas with javascript

橙三吉。 提交于 2020-01-17 02:56:05
问题 In the following code i want to rotate the text of each element of the array in javascript. If i use for example ctx.rotate(Math.PI/10) before the filltext, it rotates all the elements. The positioning of the text also changes with ctx.rotate(Math.PI/10) and if i use 90 degrees, ctx.rotate(Math.PI/2) the text does not show on the canvas. <html> <canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;"></canvas> <script> var c = document.getElementById("myCanvas"); var

Custom View not drawing properly

心已入冬 提交于 2020-01-17 02:51:06
问题 I am making an Android game which has a board with some squares (similar to a chess board). Each square has some colors and I made a custom View class in which I overrided the onDraw() method in order to draw the square in the way I want to. Each square is composed of four triangles, as you can see in the next picture, in which a board with 3x3 squares is shown: https://dl.dropboxusercontent.com/u/48529299/Impossible%20Puzzle/ic_launcher.png Each triangle can be of one of three colors: purple

微信小程序生成多张二维码以及支持async await

别来无恙 提交于 2020-01-17 02:10:28
微信小程序生成多张二维码以及支持async await 需求来了 原生小程序实现支持async await qrcode.js中引入runtime.js 使用 本次改造关键点: 1.引入runtime.js包,让原生小程序支持async await 2.修改qrcode.js里面的draw函数 2.1 返回promise对象,方便使用时是用await 接收 2.2 在draw函数绘制完成的回调函数里面,调用微信canvas 对象 api,wx.canvasToTempFilePath,直接将生成好的图片路径返回 需求来了 最近项目需要在列表里生成微信二维码,之前用的是qrcode.js,但是只是用于生成一张图片。这次网上搜了下插件,很多也都用qrcode.js,我找了个别的插件,base64-weapp-qrcode.js,使用了一下,效果很不好,决定还是用回qrcode.js。 这里要说明一点,网上看了下很多案例,基本都要使用setTimeout()延迟来接收绘制后的图片路径。这样做不太好,第一想一次性绘制多张二维码的话,实现比较麻烦,第二,我们没法确保setTimeout里面的函数执行的时候二维码一定生成好了。 不过没关系,把插件改改就好了。 原生小程序实现支持async await 想要方便的实现在列表里面绘制多张二维码,首先得让你的微信小程序支持async await

WPF 简易的跑马灯效果

半世苍凉 提交于 2020-01-17 01:47:13
原文: WPF 简易的跑马灯效果 最近项目上要用到跑马灯的效果,和网上不太相同的是,网上大部分都是连续的,而我们要求的是不连续的。 也就是是,界面上就展示4项(展示项数可变),如果有7项要展示的话,则不断的在4个空格里左跳,当然,衔接上效果不是很好看。 然后,需要支持点击以后进行移除掉不再显示的内容。 效果如下: 思路大致如下: 1、最外层用一个ViewBox,为了可以填充调用此控件的地方,这样可以方便自动拉伸 <Viewbox x:Name="viewbox_main" Height="{Binding Path=ActualHeight}" Width="{Binding Path=ActualWidth}" MouseLeave="grid_main_MouseLeave" MouseMove="grid_main_MouseMove" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stretch="Fill"/> 2、定义三个变量,一个是Count值,是为了设定要展示的UserControl的个数的,例如默认是4个,如效果图,当然,设置成5的话,就是5个了;一个List<Grid>是为了放入展示控件的列表,一个List<UserControl>是用来放所有要用于跑马灯里的控件的。 3、设置一个Canvas

c# Dragging images inside canvas in windows store app fails

寵の児 提交于 2020-01-17 01:30:30
问题 I'm fairly new to C# and programming in general. I'm building a dummy project to understand how drag and drop works. At first, I begun moving around rectangles, limiting their movements inside the canvas, and they moved just fine. After that, I tried to make it a bit more complex by adding PointerEntered/PointerExited and replacing the rectangles with images. Re-sizing the images when the events PointerEntered/PointerExited occur works, but when I try to drag my images nothing happens. I

怎样实现前端裁剪上传图片功能

瘦欲@ 提交于 2020-01-17 00:07:59
由于前端是不能直接操作本地文件的,要么通过 <input type="file"> 用户点击选择文件或者拖拽的方式,要么使用flash等第三方的控件,但flash日渐衰落,所以使用flash还是不提倡的。同时html5崛起,提供了很多的api操控,可以在前端使用原生的api实现图片的处理,这样可以减少后端服务器的压力,同时对用户也是友好的。 (笔者的个人站: http://yincheng.site/crop-upload-photo 手机端的读者推荐在这里看) 最后的效果如下: 这里面有几个功能,第一个是支持拖拽,第二个压缩,第三个是裁剪编辑,第四个是上传和上传进度显示,下面依次介绍每个功能的实现: 1. 拖拽显示图片 拖拽读取的功能主要是要兼听html5的drag事件,这个没什么好说的,查查api就知道怎么做了,主要在于怎么读取用户拖过来的图片并把它转成base64以在本地显示。 监听drag和drop事件 JavaScript 1 2 3 4 5 6 7 8 9 10 11 12 13 14 var handler = { init : function ( $ container ) { //需要把dragover的默认行为禁掉,不然会跳页 $ container . on ( "dragover" , function ( event ) { event .

移动端上传照片 预览+Draw on Canvas's Demo(解决 iOS 等设备照片旋转 90 度的 bug)

时光总嘲笑我的痴心妄想 提交于 2020-01-16 23:44:26
背景: 本人的一个移动端H5项目,需求如下:    需求一 :手机相册选取或拍摄照片后在页面上 预览    需求二 :然后 绘制在canvas 画布上 这里,我们先看一个demo( http://jsfiddle.net/q3011893/83qfqpk8/embedded/ )    需求一 : drawTempPhoto 方法    需求二 : drawPhoto 方法 操作步骤: 1、点击选择文件,拍摄一张照片,此时"预览:"文字下会显示你刚才拍摄的照片; 2、再点击"draw on Canvas",该按钮下的画布会绘制你刚才拍摄的照片。 正常的结果: -------------------------------------------------------------------------------------------------------- 正文: 1、让input file支持 拍照+相册 选取 <input accept=" image/* " type=" file " id=" file " /> //有一些特殊的安卓机还需要加上 capture="camera" 属性才能支持拍照 2、 需求一 的 预览 功能使用html5提供的新API: FileReader 介绍: FileReader 接口提供了一个异步 API ,使用该 API

How to create nxm HTML5 canvas Grid of objects (colored squares)?

99封情书 提交于 2020-01-16 17:35:31
问题 I'm trying to create a grid (matrix) of squares in a given area <canvas> with n columns and m rows, and an option to set a spacing between the squares if desired. The grid should fill squares with random coloring. I'd also like to add a zoom function, so the colored squares will appear much bigger in a region that is double-clicked. Can anyone suggest a good method to generate the grid and assign random colors to the squares? If you can suggest how to create the zoom effect too that would be

Frame in canvas will not expand to fit canvas

对着背影说爱祢 提交于 2020-01-16 14:56:21
问题 I am not sure why this will not work. I must be missing something because I can make a single frame expand to fit the canvas but I cannot make a frame inside a frame expand to fit the canvas. I have been fighting with this for hours and I feel like its something obvious. I am expecting the label inside of the NoteFrame to expand to fill the frame and that NoteFrame expand to fill the canvas. Here is the minimum code to reproduce the behavior code: import tkinter as tk class NoteFrame(tk.Frame