drawrectangle

How to add text into a pygame rectangle

回眸只為那壹抹淺笑 提交于 2019-12-19 07:38:26
问题 I have come as far as drawing a rectangle in pygame however I need to be able to get text like "Hello" into that rectangle. How can I do this? (If you can explain it as well that would be much appreciated. Thank-you) Here is my code: import pygame import sys from pygame.locals import * white = (255,255,255) black = (0,0,0) class Pane(object): def __init__(self): pygame.init() pygame.display.set_caption('Box Test') self.screen = pygame.display.set_mode((600,400), 0, 32) self.screen.fill((white

opencv rectangle with dotted or dashed lines

牧云@^-^@ 提交于 2019-12-18 05:48:07
问题 I have a line of code here that uses the python binding for opencv: cv2.rectangle(img, (box[1], box[0]), (box[3], box[2]), (255,0,0), 4) This draws a red rectangle on image img of thickness 4 . But is there a way the lines of the rectangles can be stylized? Not too much. Just dotted, or dashed, that's it really. 回答1: import cv2 import numpy as np def drawline(img,pt1,pt2,color,thickness=1,style='dotted',gap=20): dist =((pt1[0]-pt2[0])**2+(pt1[1]-pt2[1])**2)**.5 pts= [] for i in np.arange(0

Drawing rectangle using mouse events in Tkinter

谁都会走 提交于 2019-12-14 01:09:29
问题 This is with respect to Draw rectangle on mouse click [Python]. I tried out the first solution and it works perfectly. Can someone please tell me, what to do if I want to see the rectangle being drawn and the rectangle gets fixed once the mouse button is released as I can only see the drawn rectangle once the button is released. Any kind of help will be appreciated. 回答1: I amended the code from the referenced question. Now it shows the rectangle when mouse is being dragged on the canvas. The

Trying to draw a circle in Java using variable in parameters

*爱你&永不变心* 提交于 2019-12-13 18:21:59
问题 I am having trouble doing a rather simple task of taking in the diameter of a circle and then drawing it. Here is my code so far. import javax.swing.*; import java.awt.Graphics; public class Shapes extends JFrame { double diameter; public Shapes() { setSize(600,600); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void getDiameter() { String input = JOptionPane.showInputDialog("What is the diameter of the circle?"); diameter = Double.parseDouble(input); Shapes gui = new Shapes(); gui

How can I deal with overlapping rectangles? [closed]

匆匆过客 提交于 2019-12-13 08:57:56
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago . I am comparing two images and find the difference using compare_ssim, in that case I got the contours of differences, which i need to highlight by drawing rectangle around it, but I am facing the issue that some of the rectangles overlapping each other I want to remove those overlapping. Given is

Change color of graphic rectangle dynamically

无人久伴 提交于 2019-12-13 07:00:57
问题 I have write a c# class, which contains graphics inside. this is how I build the class and draw the rectangle. It works perfectly: public Graphics shape; public Rectangle rc; // constructor public CLASS_NAME(Graphics formGraphics) { this.shape = formGraphics; } public void draw(int x, int y, int w, int h) { SolidBrush myBrush = new SolidBrush(Color.Red); this.rc = new Rectangle(x, y, w, h); this.shape.FillRectangle(myBrush, rc); myBrush.Dispose(); } then I wanted to add a new method to the

Draw rectangle around Textbox inside a Groupbox

假如想象 提交于 2019-12-12 02:47:36
问题 I want to add a custom border around a TextBox control which is in a GroupBox . Since I'm new to this Graphic stuff I'm having a hard time figuring out the problem. This is the code i'm using: Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint Dim _g As Graphics = Me.GroupBox1.CreateGraphics Dim pen As New Pen(Color.Red, 2.0) _g.DrawRectangle(pen, New Rectangle(TextBox1.Location, TextBox1.Size)) pen.Dispose() End Sub This form is a secondary form that shows when I

I made a rectangle how do I check if the mouse clicked on it?

别来无恙 提交于 2019-12-12 02:12:42
问题 How do I check if a mouse clicked a rectangle? Graphics gfx; Rectangle hitbox; hitbox = new hitbox(50,50,10,10); //TIMER AT THE BOTTOM gfx.Draw(System.Drawing.Pens.Black,hitbox); 回答1: Just a sample quick and dirty, if your "gfx" is a "e.Graphics..." from a Form: public partial class Form1 : Form { private readonly Rectangle hitbox = new Rectangle(50, 50, 10, 10); private readonly Pen pen = new Pen(Brushes.Black); public Form1() { InitializeComponent(); } private void Form1_Paint(object sender

Draw rectangle and update it on every mouse click

為{幸葍}努か 提交于 2019-12-11 20:24:02
问题 Now I want to draw a rectangle on canvas on mouse click Event. Here is my code: protected void imageIR_MouseClick(object sender, System.Windows.Input.MouseEventArgs e) { ... System.Windows.Point startPoint = e.GetPosition(canvas1); rect = new System.Windows.Shapes.Rectangle { Stroke = System.Windows.Media.Brushes.LightBlue, StrokeThickness = 10 }; Canvas.SetLeft(rect, startPoint.X); Canvas.SetTop(rect, startPoint.Y); canvas1.Children.Add(rect); } private void Canvas_MouseMove(object sender,

JavaFX: How to resize a rectangle with set aspect ratio

北慕城南 提交于 2019-12-11 17:44:44
问题 I have an app where user can draw a rectangle, and resize it or move it. I'm interested if is possible to some how bind rectangles width and height in some aspect ratio. E.g. if aspect ratio is 1:2 that user can draw only that kinds of rectangles, or if is 1:1 that user can only draw square. EDIT My eventHandler for MOUSE_DRAGGED event looks something like this EventHandler<MouseEvent> onMouseDraggedEventHandler = event -> { if (event.isSecondaryButtonDown()) return; double offsetX = event