canvas

Android:Canvas中drawText的尺寸计算

女生的网名这么多〃 提交于 2020-01-23 19:19:38
主要思路:根据FontMetrica计算Text的高度,根据Rect计算Text的宽度。两者与字体,字号有关系 参考文章: http://blog.csdn.net/hursing/article/details/18703599 http://blog.csdn.net/sirnuo/article/details/21165665 1. 计算高度不应该用Rect的原因:FontMetrica与Text内容无关;Rect与Text的内容相关,用Rect计算的话会麻烦一点。paint.getTextBounds() paint.getFontMetricsInt() 2. 要正确理解FontMetrica的top,ascent,descent,bottom的含义。以上四个参数都是相对于baseLine而言的 3. 如上图:Text在Y轴的范围在:[baseLine+top,baseLine+bottom] 4. drawText(text, baseX, baseY, p aint) 中对baseX,baseY的理解:baseY即为baseLine,baseX则取决于p aint.setTextAlign(Align. LEFT )参数的设置。 5. 使用场景:Text水平,垂直都居中 package cc.makeblock.widget; import android

关于Unity中的屏幕适配

雨燕双飞 提交于 2020-01-23 17:24:46
一、Game视图的屏幕分辨率可以先自定义添加,供以后选择,以下是手游经常用到的分辨率: 1.1136X640,iPhone5 2.1920X1080,横屏,主流游戏都是这个分辨率 3.1080X1920,竖屏 4.960X640,横屏iPhone4 5.640X960,竖屏iPhone 6.768X1024,ipad 7.800X480 8.480X800 Screen Space(Overlay)模式下的Canvas节点的Rect Transform组件的Width和Height是随着Game视图的分辨率的选择而改变的,是不能手写修改的,但是其子节点的Rect Transform组件是可以改变的。 二、Image节点的Rect Transform组件是可以修改的,其中: 1.PosX,PosY,PosZ(0)表示Image节点在父节点下的相对坐标,以父节点的菊花为参照原点(0,0),可以修改菊花的位置,这时候PosX,PosY也就自动改变了。 2.ScaleX,ScaleY,ScaleZ表示Image节点的缩放,可以让节点随着自己设置的值拉伸收缩 3.Pivot:中心点,支点。定义图片的中心点在哪里,就是相当于Cocos2d里面的精灵的锚点,这个点是受PosX,Pos影响的,也就是说,这个点到父节点原点的距离就是PosX,PosY。Pivot(0,0)在左下角,Pivot(1,1

load image to fabric canvas background

邮差的信 提交于 2020-01-23 09:26:38
问题 hi im trying to upload an image and put it as canvas background. code snippet: function handleMenuImage(e){ var reader = new FileReader(); reader.onload = function(event){ var img = new Image(); img.src = event.target.result; canvas.setWidth(img.width); canvas.setHeight(img.height); canvas.setBackgroundImage(img.src, canvas.renderAll.bind(canvas)); //set the page background menuPages[currentPage].pageBackground.src = img.src; canvas.backgroundImageStretch = false; } reader.readAsDataURL(e

FabricJS - Error when loading Canvas from JSON

。_饼干妹妹 提交于 2020-01-23 09:19:06
问题 I'm using a custom object extended from fabric.Image in my canvas, as suggested in this answer. When I retrieve the json string from the server, I get odd errors when attempting to load it to the canvas: var canvas = new fabric.Canvsd(); function loadCanvas(resp) { // response object contains a data field // that's essentialy a JSON string var json = JSON.parse(resp.data); canvas.loadFromDatalessJSON(json); } I get an odd printout to the console: Cannot call method 'setupState' of undefined

canvas.toDataUrl() returns 'data:,'

穿精又带淫゛_ 提交于 2020-01-23 07:20:37
问题 I am trying to resize an image and get back the base64 string representation using canvas.toDataUrl(). My code is as follows (see below). My issue is that every time when I first initiate it, it returns 'data:,'. Then when I redo the re-sizing (calling with button), then it works fine and it returns me a nonempty base64 string. What is going on? function drawAndResizeFunction(images) var qDraw = $q.defer(); // 1 drawCanvasWrapper().then(function(canvasData){ qDraw.resolve(canvasData) }); // 2

How can I control z-index of canvas objects?

你说的曾经没有我的故事 提交于 2020-01-23 07:20:24
问题 When I draw some objects in canvas, sometimes new objects places under old ones. For example, I add some images to canvas and then draw a line. when I run code images are top of the line. I searched web for a solution. But there was not an straight-forward solution. :( In some cases, it have seen as a bug! in explorers. How can I control z-index? Edit: this is my code <img id="black_checkers_piece" src="egsdk/BlackCheckersPiece.png" style="display: none;"> <canvas id="c1" style="border:1px

Modifier inside update function HTML5 Canvas Game?

梦想与她 提交于 2020-01-23 03:30:08
问题 I've seen this kinda structure inside the update function in HTML5, Canvas games, with a "modifier" variable: function update(modifier) { obj.x += obj.speed * modifier obj.y += obj.speed * modifier } function main() { var thisLoop = new Date var delta = thisLoop - lastLoop update(delta / 1000) render() var lastLoop = new Date } var lastLoop = new Date setInterval(main, 1) Now I use myself this structure: function update() { obj.x += obj.speed obj.y += obj.speed render() window

Numpy Matrix to tkinter Canvas

时光怂恿深爱的人放手 提交于 2020-01-23 03:17:33
问题 How to display a Numpy matrix, as a bitmap, into a Tkinter canvas? More precisely, how to fill a PhotoImage with content from a matrix? photo = ImageTk.PhotoImage(...) self.canvas.create_image(0,0,image=photo,anchor=Tkinter.NW) 回答1: Here is working solution, slightly modified to make it work (some function was deprecated) and to simplify it to keep only the necessary part. We have to use Image.frombytes(...) to read the data in the numpy matrix. import Tkinter from PIL import Image, ImageTk

Tainted Canvas with canvas.toBlob

自闭症网瘾萝莉.ら 提交于 2020-01-23 01:34:06
问题 I am trying to convert a svg to an image and prompt a download to the user. var chart = $(svg.node()) .attr('xmlns', 'http://www.w3.org/2000/svg'); var width = that.svg_width; var height = that.svg_height; var data = new XMLSerializer().serializeToString(chart.get(0)); var svg1 = new Blob([data], { type: "image/svg+xml;charset=utf-8" }); var url = URL.createObjectURL(svg1); var img = $('<img />') .width(width) .height(height); img.attr('crossOrigin' ,'' ); img.bind('load', function() { var

How do you clear a polygon shaped region in a canvas element?

假装没事ソ 提交于 2020-01-23 01:33:06
问题 I've used the clearRect function, but didn't see an equivalent for polygons. I naively tried: ctx.fillStyle = 'transparent'; ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(100,50); ctx.lineTo(50, 100); ctx.lineTo(0, 90); ctx.closePath(); ctx.fill(); But that just draws a transparent region, and doesn't have an effect on what's already there. Is there a way to clear polygon regions inside of the canvas element? 回答1: You can use compositing with the operation set to 'destination-out' for this: