从文件中将图像添加到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;
相关问答
更多-
使用GROUP BY和OVER(Using GROUP BY and OVER)[2023-05-07]
你需要嵌套总和: 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 ... -
SQL:GROUP BY有一列(SQL: GROUP BY with one column)[2022-10-23]
使用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 ...
-
Apache pig group by function没有给出预期的输出(Apache pig group by function is not giving expected output)[2024-02-26]
问题是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 ...
-
MYSQL Group By列(MYSQL Group By column)[2022-02-07]
只需在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