我正在使用浏览器 HTML5 canvas 元素。
我有代码(我在网上找到)允许我在画布上绘制一个矩形。
我想在鼠标移动事件触发时应用如图所示的“阴影”效果。如何才能实现这一目标?
我当前的方法是在触发 mouseMove 事件处理程序时检查鼠标的 x 和 y 坐标。如果 x 和 y 坐标与原始坐标之间的差值大于某个预定义的增量或与矩形的宽度和高度的比率,我将尝试在 x 和 y 方向上的等距坐标之间绘制直线
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
#canvas{border:1px solid red;}
</style>
<script>
$(function(){
// get references to the canvas and context
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
// style the context
ctx.strokeStyle = "blue";
ctx.lineWidth=3;
// calculate where the canvas is on the …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个算法如下:
给定一组可能重叠的矩形(所有这些都是"未旋转",可以统一表示为(左,上,右,下)连音符等...),它返回一组最小(非旋转)非重叠的矩形,占据相同的区域.
乍一看似乎很简单,但是很容易变得棘手(至少要有效地完成).
这个/ ideas /指针有一些已知的方法吗?
不一定是最小但是启发式小的集合的方法也很有趣,所以产生任何有效输出集的方法也是如此.
algorithm graphics mathematical-optimization rectangles computational-geometry
我想问这个功能是否正确.它应检查点是否在矩形内部,如果是,则将其打印出来.
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int x;
int y;
}point;
typedef struct {
point A;
point B;
}rectangle;
int main() {
rectangle s;
point T;
printf("Enter rectangle A point x coordinate :\n" );
scanf("%d", &s.A.x);
printf("Enter rectangle A point y coordinate :\n" );
scanf("%d", &s.A.y);
printf("Enter rectangle B point x coordinate :\n" );
scanf("%d", &s.B.x);
printf("Enter rectangle B point y coordinate :\n" );
scanf("%d", &s.B.y);
printf("\nrectangle - A(%d, %d), B(%d, %d) \n", s.A.x, s.A.y, s.B.x, s.B.y ); …Run Code Online (Sandbox Code Playgroud) 如何在MonoGame中绘制形状,例如矩形和圆形,而不必在"内容"文件夹中保存预先绘制的形状?
DrawRectangle()和DrawEllipse()适用于Windows窗体,不适用于我正在使用的OpenGL.
我正在尝试在画布内移动一个动态绘制的矩形.我能够在画布中动态绘制矩形,同时尝试在画布内移动矩形我遇到问题
XAML:
<Grid x:Name="Gridimage1" Margin="0,0,411,100">
<Image Name="image1" HorizontalAlignment="Left" Stretch="Fill" VerticalAlignment="Top"></Image>
<Canvas x:Name="BackPanel" Margin="20,67,0,0" Height="317" Width="331">
<Rectangle x:Name="selectionRectangle" Stroke="LightBlue" Fill="#220000FF"/>
</Canvas>
</Grid>
Run Code Online (Sandbox Code Playgroud)
C# :
动态绘制矩形后,我正在添加以下鼠标事件.
selectionRectangle.MouseLeftButtonDown += new MouseButtonEventHandler(Rect1_MouseDown);
selectionRectangle.MouseMove += new MouseEventHandler(Rectangle_MouseMove_1);
selectionRectangle.MouseUp += new MouseButtonEventHandler(Rect1_MouseUp);
# region "rectangle move"
private bool drag = false;
private Point startPt;
private int wid;
private int hei;
private Point lastLoc;
private double CanvasLeft, CanvasTop;
private void Rect1_MouseDown(object sender, MouseButtonEventArgs e)
{
drag = true;
Cursor = Cursors.Hand;
startPt = e.GetPosition(BackPanel);
wid = (int)selectionRectangle.Width; …Run Code Online (Sandbox Code Playgroud) 我是OpenLayers的新手,对于一个明显的(也许是愚蠢的)问题感到抱歉,为此我找到了解决方案的不同方法,但都没有工作.试过这个和那个,十几个不同的建议(这里,这里,这里,这里,这里)但是徒劳无功.
基本上,我想将绘制的矩形的坐标传递给另一个Web服务.因此,在绘制矩形后,它应该将我吐出边界框的四个角.
到目前为止我所拥有的是绘制矩形的基本OL图层示例:
var source = new ol.source.Vector({wrapX: false});
vector = new ol.layer.Vector({
source: source,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(0, 255, 0, 0.5)'
}),
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 2
}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vector
],
view: new ol.View({
center: …Run Code Online (Sandbox Code Playgroud) 我尝试使用此处显示的算法:https://discuss.leetcode.com/topic/15733/my-java-solution-sum-of-areas-overlapped-area
然而,该算法仅涉及找到仅两个重叠矩形的区域.
如果我知道每个矩形的长度和宽度,我将如何继续找到3个,4个或5个等重叠矩形的交叉区域?
我正在尝试通过使用半径(rx,ry)在svg中创建一个在顶部和底部具有边框/笔触和圆角的矩形。通过使用css属性“ dasharray:width,height”,可以仅使用边框/笔触对顶部和底部进行样式设置。没有半径,则按预期工作。
但是,添加半径后,顶部边框不再从矩形的左上角开始。我试图通过使用css属性dash-offset来纠正此问题,但这似乎会使顶部边框部分消失(尽管它似乎适用于底部边框)。
我们非常感谢您提供有关如何创建一个半径仅为顶部和底部边框的矩形的帮助,以及对正在发生的情况的一些了解。
看到小提琴:https : //jsfiddle.net/Lus8ku7p/
<svg>
<rect x =10 y=10 id=a ></rect>
<rect x = 10 y=170 id=b class=round></rect>
<rect x=170 y=10 id=c ></rect>
<rect x=170 y=170 id=d class=round></rect>
</svg>
svg{
width:400px;
height:400px
}
rect {
width: 150px;
height: 150px;
stroke-width:4px;
stroke:black;
fill:red;
stroke-dasharray: 150 150;
}
.round{
rx:20px;
ry:20px;
}
#c, #d{
stroke-dashoffset: 40px;
}
Run Code Online (Sandbox Code Playgroud) 如何从成功的VNRectangleObservation对象拍摄照片(获取CIImage)?
我有一个视频捕获会话正在运行,func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)我正在处理,即
func captureOutput(_ output: AVCaptureOutput,
didOutput sampleBuffer: CMSampleBuffer,
from connection: AVCaptureConnection) {
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
do {
try handler.perform([request], on: pixelBuffer)
} catch {
print(error)
}
}
Run Code Online (Sandbox Code Playgroud)
我应该在哪里保存我传递给处理程序并在该缓冲区上操作的像素缓冲区?遗憾的是,我无法从观察对象访问图像作为属性:(
有任何想法吗?
rectangles ×10
c# ×2
algorithm ×1
area ×1
c ×1
canvas ×1
coordinates ×1
cornerradius ×1
fade ×1
geometry ×1
graphics ×1
html ×1
html5-canvas ×1
ios ×1
javascript ×1
line ×1
monogame ×1
openlayers-3 ×1
point ×1
python ×1
qml ×1
qt ×1
svg ×1
wpf ×1