Reputation: 202
I've been trying to get all the pixels of a line which is being drawn by a user into an array.
I will later try to make an analysis of this line so it is very important that I don't miss any pixels. With the code I use currently it misses quite a few pixels. The problems should be in the way that graphics creates lines and not individual pixels. The pixels that are set, are saved into the image1Pixel
array. Here is my myMouseDragPaint
function in which I save the lines into the array.
Does anyone know how I can change this so I won't miss any pixels?
If you need any additional information regarding this question, please don't hesitate to ask.
Thank you,
Miza
Upvotes: 0
Views: 781
Reputation: 34518
You are saving only line vertexes in your code, missing all pixels between them:
image1Pixel[currX][currY] = 1; // line vertex
G.drawLine(prevX, prevY, currX, currY); // this draws a whole line, no just two vertex points
You need to either:
Also, note that lines don't cover single pixels (except exactly vertical or horizontal ones). So second option will work better for you, because you will not repeat drawing math after graphical library.
Upvotes: 1