canvas

Improve performance of Canvas.drawBitmap() on android

早过忘川 提交于 2019-12-24 06:34:02
问题 Going with the time I try to implement view pager in my tile based game - and swiping is janky. I performed necessary performance measures like suggested by @romangui , and found out that redrawing my gaem field takes about 48 msec (way too long) - and I already flattened layout, eliminated overdraw have my custom layout managers etc. I discovered that drawing one tile on GN takes about 0.600 msec - way too long for all 81 tiles. Time is actually spend on Canvas.drawBitmap(...) Any ideas how

javascript loaded image is blurry (PNG)

耗尽温柔 提交于 2019-12-24 06:25:10
问题 I am working on a school project (only couple months of JS knowledge), and i stumbled upon this problem with drawing sprites on my canvas. To draw i use these bits of code. treeImage = new Image(); treeImage.src = "sprites/treeSprites.png"; function rocks() { //to create the rock this.x = 1920 * Math.random(); //random location on the width of the field this.y = ground[Math.round(this.x/3)]; //ground is an array that stores the height of the ground this.draw = function() { ctx.save(); ctx

Picasso Circle Transformation without Cropping Image

♀尐吖头ヾ 提交于 2019-12-24 05:59:46
问题 How do I make Circle Transformation without cropping the image? I've been trying for 2 days and I keep failing. This is the closest I've come so far, but as you can see, the image is not centered inside the circle. @Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); Bitmap squaredBitmap = Bitmap.createScaledBitmap(source,size-50, size-50,true); if (squaredBitmap != source) { source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size

canvas.drawLine() not appearing on bitmap

瘦欲@ 提交于 2019-12-24 05:55:18
问题 I have tried so many methods but still my code refuses to simply draw a line on the canvas. Each of the attempts I have commented out either crash the program or won't display the line. I am really struggling to get my head around how to do this, I keep getting different advice on using threads or onDraw or whatever, but none seem to work. My overall objective is to display a bitmap image on the screen, and draw lines on top of it. I then wish to use canvas.tranlate to make the entire image

How to generate CMY triangle for the browser? (CSS, SVG, Canvas?)

一笑奈何 提交于 2019-12-24 04:57:10
问题 I am trying to produce a CMY triangle for a project. I would like to be able to render it directly on the web using either css, a svg or canvas. Based on Amelia's comment, I tried building a CSS (SASS) class to render the triangle with linear-gradients. .triangle { @include background-image( linear-gradient(to bottom, rgba(0, 252, 253, 1), rgba(0, 252, 253, 0.25) 50%, rgba(0, 252, 253, 0) 86.6%), linear-gradient(-60deg, rgba(250, 11, 247, 1), rgba(250, 11, 247, 0.25) 50%, rgba(250, 11, 247, 0

Access raw YUV values from JPEG with JavaScript

梦想与她 提交于 2019-12-24 04:55:30
问题 I have dynamically loaded a JPEG image into a 2D html canvas and I would like to access the raw YCbCr pixel values. From what I understand, JPEG encodes the pixel data in YCbCr, but chrome appears convert it to RGB when accessing it with getImageData(). I have tried using the RGB to YCbCr conversion calculations but it appears to be a lossy conversion as they don't map perfectly 1-to-1. Is it possible to access the raw YCbCr pixel values in JavaScript? 回答1: Yes and no. When the browser loads

How to draw the below image in android programatically?

十年热恋 提交于 2019-12-24 04:54:10
问题 I am new to android. I'm finding very difficulty in using the Canvas. How to draw the below image in android? I also want to make the alphabet selected highlighted when it is touched. 回答1: Here it is: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="64dp" android:background="#000"> <!--

Html5 Canvas 扫雷 (IE9测试通过)

落爺英雄遲暮 提交于 2019-12-24 04:43:03
扫雷是一个非常经典的游戏,记得在第一次接触的windows 3.22 上就有扫雷了,到现在的Win7,依然保留着这个经典的游戏,结合Html5 Canvas,模仿Win7的UI,将老板扫雷进行了升级。在 FireFox, Chrome, 和 IE9 下测试通过。 实现中设计的类: CellInfo, MineInfo, InfoProcess, CellRender, MineArea, GameInfo, GameStatus, Game, StorageInfo, GameStorage。 游戏界面: GameMode: Beginner 初级设置 Width:7 Height:7 Mine:10。 Intermediate 中级设置 Width:15 Height:15 Mine:40。 Expert 高级设置 Width:30 Height:15 Mine:99。 Random 随机模式。 CustomerSetting: 用户自定义扫雷的 Width Height Mine。 Performance Test: 测试游戏在浏览器上的反应。 Game Record: 游戏记录。 Pause: 暂停游戏。 Save: 存盘游戏。 当点击Save存盘后,在GameStorage下面会记录当前游戏的缩略图。鼠标进入存盘缩略图,当前缩略图高亮一个小红边,点击左键恢复存盘点

How to display a smoother gradient in HTML5 canvas?

白昼怎懂夜的黑 提交于 2019-12-24 04:27:39
问题 I have a html5 canvas in my web page. I have only put an image and a gradient in it. Canvas uses thic JS code to draw itself: var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.clearRect ( 0 , 0 , canvas.width, canvas.height ); var img = document.getElementById("slika"); ctx.drawImage(img, 0, 0,canvas.width,canvas.height); var grd = ctx.createLinearGradient(x-400, 0, x, 0) grd.addColorStop(0.3,"hsla(360, 100%, 100%, 0)"); grd.addColorStop(1,"hsla(360, 100

Degree text needs to be aligned in javascript

↘锁芯ラ 提交于 2019-12-24 04:23:36
问题 In this fiddle the four pink dots movable[its draggable]. it forms any polygon shape. while clicking the draw button it draw each corner angle. this will be fine. but i need a degree text infront of the arc. Existing one: I need like this: ctx.save(); ctx.beginPath(); ctx.moveTo(b1, b2); ctx.arc(b1, b2, 20, ax1, ax2, !isInside); console.log(ax1, ax2); ctx.closePath(); ctx.fillStyle = "red"; ctx.globalAlpha = 0.25; ctx.fill(); ctx.restore(); ctx.fillStyle = "black"; ctx.fillText((isInside ? a