canvas

Canvas javascript drawImage method

被刻印的时光 ゝ 提交于 2021-01-29 02:00:02
问题 Result : It doesn't load the image to the canvas. I'm getting white rectangle, any idea why? I thought I could just call the draw method directly from the variable , like e.g : bg.draw, or does that mean that I need to re-draw the Image again on the canvas and re-run the bg.draw? const cvs = document.getElementById("firstplatform"); const ctx = cvs.getContext("2d"); // GAME VARS AND CONSTS let frames = 0; // LOAD IMAGE const sprite = new Image(); sprite.src = "img/sprite.png"; //BACKGROUND

fabric.js: bind event to background image

痞子三分冷 提交于 2021-01-28 23:38:08
问题 I'm trying to bind an event to a background image: var imgInstance = fabric.Image.fromURL(path, function(oImg) { oImg.on("selected", function() { alert(); }); canvas.setBackgroundImage(oImg, canvas.renderAll.bind(canvas), { top: 0, left: 0 }); oImg.on("selected", function() { alert(); }); }); I can get it work. I'm trying to bind mouse events to handle drag, so i can move the image when it's bigger than the canvas, like background-cover css property. Thoughts? Thanks guys! SOLUTION: var

fabric.js: bind event to background image

浪子不回头ぞ 提交于 2021-01-28 23:37:10
问题 I'm trying to bind an event to a background image: var imgInstance = fabric.Image.fromURL(path, function(oImg) { oImg.on("selected", function() { alert(); }); canvas.setBackgroundImage(oImg, canvas.renderAll.bind(canvas), { top: 0, left: 0 }); oImg.on("selected", function() { alert(); }); }); I can get it work. I'm trying to bind mouse events to handle drag, so i can move the image when it's bigger than the canvas, like background-cover css property. Thoughts? Thanks guys! SOLUTION: var

Make HTML Canvas generate PDF-ready Line art?

眉间皱痕 提交于 2021-01-28 21:26:31
问题 I have an HTML/JavaScript program that uses the HTML5 canvas to generate a pretty graph: I want to include this graph in a book that I'm producing with LaTeX. Unfortunately, when I print this page to PDF, I get a bitmap—presumably because canvas is a bitmap. I just checked and apparently if I had developed this with SVG instead of with HTML5 canvas I would be good to go. But I didn't. So is there any way to generate line art from HTML5 Canvas, or should I just bite the bullet and re-implement

Zooming canvas on mobile

Deadly 提交于 2021-01-28 19:15:25
问题 I have a page where a user can upload a photo. Once uploaded they can move it in a canvas and they can crop the image that is over the canvas. To crop it, I get the image coordinates relative to the canvas and i convert it with toDataURL . On mobile devices I use zoom in CSS to scale the whole canvas to fit the viewport. I cannot do it in another way because besides the user's photo, the are other elements and various texts that are impossibile to scale to fit each resolution. The problem is

Canvas with BitmapCache - Render after removing child

徘徊边缘 提交于 2021-01-28 17:37:40
问题 I have a user control that contains the following elements: <UserControl ...> <ScrollViewer Name="LayoutScroll" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"> <Grid Name="MainGrid"> <Canvas x:Name="LayerObjects" Panel.ZIndex="2" Width="{Binding ActualWidth,ElementName=MainGrid}" Height="{Binding ActualHeight, ElementName=MainGrid}"> <Canvas.CacheMode> <BitmapCache EnableClearType="False" SnapsToDevicePixels="False" RenderAtScale="2"/> </Canvas.CacheMode> </Canvas> <

Canvas with BitmapCache - Render after removing child

*爱你&永不变心* 提交于 2021-01-28 17:36:10
问题 I have a user control that contains the following elements: <UserControl ...> <ScrollViewer Name="LayoutScroll" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"> <Grid Name="MainGrid"> <Canvas x:Name="LayerObjects" Panel.ZIndex="2" Width="{Binding ActualWidth,ElementName=MainGrid}" Height="{Binding ActualHeight, ElementName=MainGrid}"> <Canvas.CacheMode> <BitmapCache EnableClearType="False" SnapsToDevicePixels="False" RenderAtScale="2"/> </Canvas.CacheMode> </Canvas> <

How do I center a rectangle on a canvas

半城伤御伤魂 提交于 2021-01-28 12:19:20
问题 I have the vaguest idea why this block of code won't center the rectangle on the canvas. It even ends up being drawn out of bounds. Please help? document.addEventListener('DOMContentLoaded', drawIllustrations); function drawIllustrations(e) { var fixedBody = document.getElementById('FixedBody'), contextOne = fixedBody.getContext('2d'), centerX = fixedBody.offsetWidth * 0.5; contextOne.fillStyle = "#BFFF00"; contextOne.fillRect(centerX - 100,0,200,fixedBody.offsetHeight); } 回答1: To center the

How to click the center of the canvas in Java Selenium Driver?

纵饮孤独 提交于 2021-01-28 11:28:39
问题 I'm trying to write the code to click a canvas center in the web page. Here is the code below: private static void clickCanvasCenter() { WebElement we = driver.findElement(By.tagName("canvas")); int x = we.getSize().width/2; int y = we.getSize().height/2; Actions builder = new Actions(driver).moveToElement(new WebDriverWait(driver,20) .until(ExpectedConditions.elementToBeClickable(we))); System.out.println("width:" + x + "\theight:" + y); builder.click().build().perform(); System.out.println(

Fabric js render of big image gives pixelated results

痴心易碎 提交于 2021-01-28 11:10:32
问题 I have to fit a big image (8000x6500) into a 800x650 canvas When I try to render the image simply using canvas.add() and having the image render at its 100% scale the resulting image is much more pixelated/blurred compared to the original one. This is the code I'm using (only the image is a little bit smaller but you can still see the issue): const canvas = new fabric.Canvas('c', { imageSmoothingEnabled: false }); fabric.Image.fromURL('http://cms.web.cern.ch/sites/cms.web.cern.ch/files/styles