How to get the coordinates for drawing in GDI+

The question was asked: 7 years 2 months ago   views: 45
0

Hello. I'm using the FillClosedCurve method to draw shapes on the points.

Dim BM As New Bitmap(1000, 1000) Dim G As Graphics = Graphics.FromImage(BM) G. SmoothingMode = Drawing2D.SmoothingMode.AntiAlias G. FillClosedCurve(Brushes.Black, points_array) PictureBox1.BackgroundImage = BM

To retrieve the points use the following principle : put the picture on the background of the form and pressing the form X and Y of the cursor is added to a list of points. I need to draw a treble clef , please tell me how comfortable you can get a list of points to build , maybe how to get them from png file ?

Asked: 24-08-2012 в 22:39:01

Answers   1

0

I found a solution. I checked in a cycle all pixels png file on alpha != 0 (I have the image without the background) , received the list of non-transparent pixels (750 x,y pairs) , and poured in a loop black color

Dim gr As Graphics = PictureBox2.CreateGraphics Dim bmp As Bitmap = PictureBox1.Image Dim spoints as string as /* get the pixels of the image from PictureBox1 */ For i = 0 To bmp.Size.Height - 1 For j = 0 To bmp.Size.Width - 1 If bmp.GetPixel(j, i).A <> 0 Then gr.FillRectangle(Brushes.Black, j, i, 1, 1) spoints &= j & ""& i & " " End If Next Next /* draw the points */ spoints = spoints.trim() Dim gr As Graphics = PictureBox3.CreateGraphics Dim points_array() As String = spoints.Text.Split For i = 0 To points_array.Count - 2 Step 2 gr.FillRectangle(Brushes.Black, CSng(points_array(i)), CSng(points_array(i + 1)), 1, 1) Next
Answered: 25-08-2012 в 01:39:44