canvas

How to make Tkinter GUI thread safe?

非 Y 不嫁゛ 提交于 2019-12-31 02:53:08
问题 I have written a piece of code where I have a simple GUI with an canvas. On this canvas I draw a Matplot. The Matplot is updated every second with data from an SQ Lite DB which I fill with some fake Sensor information (just for testing at the moment). My Problem was that the redrawing of the canvas causes my window/gui to lag every second. I even tried to update the plot in another thread. But even there I get an lag. With my newest Code i got most of my things working. Threading helps to

Canvas - floodfill leaves white pixels at edges

我怕爱的太早我们不能终老 提交于 2019-12-31 01:05:31
问题 I am creating a drawing app. I have succeeded to do everything. When I paint the image with a dark color, some white pixels appear at the edges. I tried to change the value of r + g + b and also alpha but no use. Can any one help me out? You can check the live site from here. Anyone who will help me, I shall grant 50 bounty to him/her. Thanks. This is my code. <script type="text/javascript"> var initial = screen.width - 50; if (initial < 1000) { initial = 1000; } var firsttime = null; var

Android: UI elements over canvas layer

≯℡__Kan透↙ 提交于 2019-12-31 00:45:34
问题 How do I set some UI elements over (on top of) canvas? I have a simple touch game that has its graphics placed on custom view with canvas. However as my full screen Panel is in the setContentView() I can't add any UI items like progressBar or logo. I would like to have whole canvas layer visible with some objects (progressBar, logo) "floating" over it. Main class: public class GameClass extends Activity implements OnGestureListener { Panel panel; public void onCreate(Bundle savedInstance) {

How to draw border around canvas

≯℡__Kan透↙ 提交于 2019-12-30 23:01:50
问题 I am drawing an image on a canvas with white background color. I want to draw a border around the canvas and I am unable to do so. Here is my code: canvas.width = image.width; canvas.height = image.height; var context = canvas.getContext('2d'); context.fillStyle = "black"; context.font = "50px Arial"; context.fillText(chartId, 0, 50); context.drawImage(image, 0, 0); context.globalCompositeOperation = "destination-over"; context.fillStyle = "#FFFFFF"; context.fillRect(0,0,canvas.width,canvas

How to convert a png base64 string to pixel array without using canvas getImageData?

让人想犯罪 __ 提交于 2019-12-30 20:01:13
问题 Although it seems that this question has been asked before, people rely on canvas for that conversion. The problem is going from a base64 url like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAAFElEQVQIW2NkYGD4D8RYAeOQkgQAERQHAbuZaGoAAAAASUVORK5CYII= to a pixel array with color intensities like this var array = [ [0x00,0x00,0x00], ... 49 times ]; for a 7px by 7px image (black in that case), we have to use code like this: var mCanvas = document.createElement(

Android Convert view to BitMap

淺唱寂寞╮ 提交于 2019-12-30 12:39:16
问题 I'm trying to convert a view to bitmap but I lose the black color. I'm converting like this: Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(),view.getHeight(), Bitmap.Config.ARGB_8888); Example How can i convert to bitmap so the black of the percentage value is not lost? Thanks, Regards 回答1: Hi you can use this method to convert View to Bitmap private Bitmap createBitmapFromView(Context context, View view) { DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity) context)

How to control animation speed (requestAnimationFrame)?

三世轮回 提交于 2019-12-30 11:13:31
问题 I change the text color with requestAnimationFrame(animate); function: requestAnimationFrame(animate); function animate(time){ ... // change text color here if (offset_s < offset_e) {requestAnimationFrame(animate);} } offset_s and offset_s indicates start and end positions of the text for color change. In some cases the animation should last for 2 seconds, but in order cases - for 5 seconds, but offset_e - offset_s could be the same in these two cases. What can I do to control the speed of

How to get a canvas relative mouse position of a CSS 3D transformed canvas?

巧了我就是萌 提交于 2019-12-30 11:02:26
问题 Just for fun I'm trying to draw on 3D transformed canvases. I wrote some code and it kind of works const m4 = twgl.m4; [...document.querySelectorAll('canvas')].forEach((canvas) => { const ctx = canvas.getContext('2d'); let count = 0; canvas.addEventListener('mousemove', (e) => { const pos = getElementRelativeMousePosition(e, canvas); ctx.fillStyle = hsl((count++ % 10) / 10, 1, 0.5); ctx.fillRect(pos.x - 1, pos.y - 1, 3, 3); }); }); function getElementRelativeMousePosition(e, elem) { const pos

Canvas gradient performance

断了今生、忘了曾经 提交于 2019-12-30 10:57:05
问题 I am currently programming a little game using canvas. For the game I need some kind of fog which hides the most part of the map and only a small area around the player should be visible. Therfor I use a second canvas to overlay the one where the game takes place and fill it with a gradient (from transparent to black): function drawFog(){ fogc.clearRect(0,0,700,600); // Create gradient var grd=fogc.createRadialGradient(player.getPosX(),player.getPosY(),0,player.getPosX(),player.getPosY(),100)

How to drag and drop from one HTML5 canvas to another

删除回忆录丶 提交于 2019-12-30 10:35:09
问题 I'm trying to figure out how to drag and drop an image from one canvas to another canvas. Assuming the canvases are next to each other, would it be possible to seamlessly drag something across the border? If not, is it a better idea to drag a div over the canvas, get its ID, and place it by responding to the mouseup location on the canvas? 回答1: You don't drag items on a canvas. A canvas is a non-retained mode (or immediate mode ) graphics API. You issue draw commands and you get pixels.