首页 \ 问答 \ 从文件中将图像添加到HTML5 Canvas(Add image to HTML5 Canvas from a file)

从文件中将图像添加到HTML5 Canvas(Add image to HTML5 Canvas from a file)

在HTML5 Canvas中我试图添加和图像。 这条线:

 imageObj.src = 'file://C:/Users/User/Documents/Image File/image1.jpg';

是不正确的。 如何将文件添加到HTML5 Canvas图像?

  <canvas id="myCanvas" width="1000" height="1000"></canvas>
  <script>
        var canvas = document.getElementById('myCanvas');
        var context = canvas.getContext('2d');
        var centerX = canvas.width / 2;
        var centerY = canvas.height / 2;
        var imageObj = new Image();
        imageObj.src = 'file://C:/Users/User/Documents/Image File/image1.jpg';
        imageObj.onload = function () {
            context.drawImage(imageObj, centerX, centerY);
        };
   </script>

In HTML5 Canvas I am trying to add and image. The line:

 imageObj.src = 'file://C:/Users/User/Documents/Image File/image1.jpg';

is not correct. How do I add a file to HTML5 Canvas Image?

  <canvas id="myCanvas" width="1000" height="1000"></canvas>
  <script>
        var canvas = document.getElementById('myCanvas');
        var context = canvas.getContext('2d');
        var centerX = canvas.width / 2;
        var centerY = canvas.height / 2;
        var imageObj = new Image();
        imageObj.src = 'file://C:/Users/User/Documents/Image File/image1.jpg';
        imageObj.onload = function () {
            context.drawImage(imageObj, centerX, centerY);
        };
   </script>

原文:https://stackoverflow.com/questions/36772219
更新时间:2022-07-23 10:07

最满意答案

你可以通过自我加入实现这一目标。 我们的想法是,您构建一个子选择,为每个id提供最小值,然后通过id将其连接到原始表。

SELECT a.id, a.value-b.min_value
FROM "table" a INNER JOIN
    (SELECT id, MIN(value) AS min_value FROM "table" GROUP BY id) AS b
    ON a.id = b.id;

You can achieve this with a self join. The idea is that you build a subselect that gives you the minimum value for each id, and then join that to the original table by id.

SELECT a.id, a.value-b.min_value
FROM "table" a INNER JOIN
    (SELECT id, MIN(value) AS min_value FROM "table" GROUP BY id) AS b
    ON a.id = b.id;

相关问答

更多
  • 你需要嵌套总和: SELECT Year, Country, SUM([Total Sales]), SUM(SUM([Total Sales])) OVER (PARTITION BY Year) FROM Table GROUP BY Country, Year; 第一次看到它时,这种语法有点时髦。 但是,窗口函数在GROUP BY 之后进行评估。 这说的是总销售额的总和。 。 。 正是你想要的。 You need to nest the sums: SELECT Year, Coun ...
  • 使用MAX : SELECT name, MAX(id1) AS id1, MAX(id2) AS id2, MAX(id3) AS id3, MAX(id4) AS id4 FROM tbl GROUP BY name; Use MAX: SELECT name, MAX(id1) AS id1, MAX(id2) AS id2, MAX(id3) AS id3, MAX(id4) AS id4 FROM tbl GROUP ...
  • 你可以用case based aggregation做到这一点 SELECT BatchName,SubBatchName, Count(RecordId)AS Records, sum(case when Opstatus1='D' then 1 else 0 end) as DE1, sum(case when Opstatus2='D' then 1 else 0 end) as DE2 FROM Tbl_12042014 GROUP BY BatchName, SubBatchName you ...
  • 问题是PigStorage没有考虑转义,因此为不应该是列的字段创建列(每次条目包含逗号)。 使用CSVExcelStorage将解决此问题,因为此存储可以处理转义,从而创建正确的数量和列序列。 The problem is that PigStorage does not take escaping into account, so creates columns for fields that should not be columns (each time an entry contains a com ...
  • 您可以在GROUP_CONCAT使用DISTINCT : select pp.productsid , group_concat(DISTINCT p.productsname) from purchaseproducts pp join products p on find_in_set(p.productsid,pp.productids); GROUP BY pp.productsid You can simply use DISTINCT inside the GROUP_CONCAT : ...
  • 您可以使用HAVING子句执行此操作: SQL小提琴 SELECT a FROM tbl GROUP BY a HAVING SUM(CASE WHEN b IS NOT NULL OR c = 0 THEN 1 ELSE 0 END ) = 0 You can do this using HAVING clause: SQL Fiddle SELECT a FROM tbl GROUP BY a HAVING SUM(CASE ...
  • 您可以使用视图来模拟1NF表,然后它会很简单。 CREATE VIEW tempView AS SELECT GroupID, Defect1 AS Defect, Run FROM Product UNION ALL SELECT GroupID, Defect2 AS Defect, Run FROM Product UNION ALL SELECT GroupID, Defect3 AS Defect, Run FROM Product GO SELECT GroupID, Defect, ...
  • 你可以通过自我加入实现这一目标。 我们的想法是,您构建一个子选择,为每个id提供最小值,然后通过id将其连接到原始表。 SELECT a.id, a.value-b.min_value FROM "table" a INNER JOIN (SELECT id, MIN(value) AS min_value FROM "table" GROUP BY id) AS b ON a.id = b.id; You can achieve this with a self join. The id ...
  • 我不认为你可以通过“嵌套”SQL语句并将它们与UNION连接来获得所需的结果。 根据您的要求,此结构可能有效: SELECT 'Name1' AS Label , COUNT(*) AS The_Count FROM table1 WHERE ... UNION ALL SELECT 'PROGR2R2PST', COUNT(*) FROM table2 WHERE ... UNION ALL SELECT 'Name3', COUNT(*) FROM table3 ...
  • 只需在group by子句中添加类型即可。 既然你没有提供列名,我会猜到: GROUP BY t.type, u.ownership Just add the type in the group by clause. Since you didn't provide the columns name I'll guess something like : GROUP BY t.type, u.ownership

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)