Jump to content
You must now use your email address to sign in [click for more info] ×

How To Draw a One-Pixel Opaque Line


Recommended Posts

I'm having trouble drawing single-pixel, opaque, non-antialiased lines. I can't find a way to turn anti-aliasing off, and the lines are either more than one pixel wide or partially transparent. I'm only talking about horizontal and vertical lines.

In the attached screen capture, the line on the far right is a curve with a 1-pixel white stroke on a dark gray background. The line is vertical, but you can see it is more than one pixel wide, and it's not white. The line on the far left is a filled pixel selection. It looks correct, a single pixel wide and opaque white, but if I move it (the line second from the left), its width and color changes. I need to create a single-pixel line that's not transparent and a known color, like the line second from the right imported as part of a Photoshop document.

Lines.jpg

Link to comment
Share on other sites

It depends of the position of the line.

A line made by the Pen Tool, for example, has two sides. If it's a single pixel wide, it will have half a pixel for one side and half a pixel for the other. For it to be a perfect straight line fitting in a pixel, you have to position the center of the line in the center of the pixel.

Look at the screenshot:

  • The upper line has been made position its beginning and its end at .5 value on the Y axis.
  • The other one, at a round number/position in the canvas.

image.png.9392d06dce283cc285ea7aab84cdf846.png

Best regards!

 

 

Link to comment
Share on other sites

"You'll never know what you can do until you get it up as high as you can go! I keep telling my missus this but all I get is daggers ¬¬ :D

 

iMac 27" 2019 Somona 14.3.1, iMac 27" Affinity Designer, Photo & Publisher V1 & V2, Adobe, Inkscape, Vectorstyler, Blender, C4D, Sketchup + more... XP-Pen Artist-22E, - iPad Pro 12.9  
B| (Please refrain from licking the screen while using this forum)

Affinity Help - Affinity Desktop Tutorials - Feedback - FAQ - most asked questions

Link to comment
Share on other sites

2 hours ago, firstdefence said:

I keep telling my missus this but all I get is daggers

So do you mean she is averse to loggins to the danger zone?  9_9

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

Link to comment
Share on other sites

  • 4 weeks later...
On 3/30/2019 at 12:07 PM, Mithferion said:

It depends of the position of the line.

So it's not possible to draw a precise, single-pixel line in an arbitrary position? What about filling a one-pixel wide selection? Why does that also depend on position? Shouldn't a filled selection include all the pixels within the selection, and none outside, with the same color/transparency? It looks like it's doing antialiasing whether I want it to or not.  Is it not possible to do precision, pixel-perfect drawing?

Link to comment
Share on other sites

When you do this in Illustrator, it positions the line for you at half the pixel, so, it’s the same principle.

Understanding pixels and vector is essential to understand this.

Best regards!

Link to comment
Share on other sites

A short gif to demo what Mithferion is talking about.
Pixel-Line-Demo.gif

iMac 27" 2019 Somona 14.3.1, iMac 27" Affinity Designer, Photo & Publisher V1 & V2, Adobe, Inkscape, Vectorstyler, Blender, C4D, Sketchup + more... XP-Pen Artist-22E, - iPad Pro 12.9  
B| (Please refrain from licking the screen while using this forum)

Affinity Help - Affinity Desktop Tutorials - Feedback - FAQ - most asked questions

Link to comment
Share on other sites

7 hours ago, John-B said:

So it's not possible to draw a precise, single-pixel line in an arbitrary position?

If by arbitrary position you mean a straight line at any arbitrary angle (not just those aligned to the horizontal or vertical axis), then no that is not possible, not even with Illustrator's Align to Pixel Grid options.

7 hours ago, John-B said:

Shouldn't a filled selection include all the pixels within the selection, and none outside, with the same color/transparency?

What kind of selection do you mean? Vector objects are not defined by how many whole or partial pixels they fill; instead they are defined by the geometry of a path, which could consist of any number of straight and/or curved segments. So for example, an elliptical or circular vector object has no straight line segments at all; a rounded rectangle could have any combination of straight & curved segments depending on the geometry of its corners; & a vector path can have a stroke that is not a constant width anywhere over its entire length.

Vector objects can also be rotated to any arbitrary angle & their fills & strokes can have continuously variable color and/or transparent gradients. They can be masked or clipped by other vector objects, each defined by the geometry of its path, & whatever colors & transparencies it may have.

Because they are not defined by how many pixels they fully or partially fill, you can't really select just some of their pixels or just some of the  color, transparency, stroke or fill properties of those pixels like you can with pixel-based rasterized objects.

BTW, much the same thing applies to text objects because their properties are also not defined strictly by how many pixels they fill.

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

Link to comment
Share on other sites

On 4/22/2019 at 5:43 AM, R C-R said:

If by arbitrary position you mean a straight line at any arbitrary angle (not just those aligned to the horizontal or vertical axis), then no that is not possible, not even with Illustrator's Align to Pixel Grid options.

What kind of selection do you mean? Vector objects are not defined by how many whole or partial pixels they fill; instead they are defined by the geometry of a path, which could consist of any number of straight and/or curved segments. So for example, an elliptical or circular vector object has no straight line segments at all; a rounded rectangle could have any combination of straight & curved segments depending on the geometry of its corners; & a vector path can have a stroke that is not a constant width anywhere over its entire length.

Vector objects can also be rotated to any arbitrary angle & their fills & strokes can have continuously variable color and/or transparent gradients. They can be masked or clipped by other vector objects, each defined by the geometry of its path, & whatever colors & transparencies it may have.

Because they are not defined by how many pixels they fully or partially fill, you can't really select just some of their pixels or just some of the  color, transparency, stroke or fill properties of those pixels like you can with pixel-based rasterized objects.

BTW, much the same thing applies to text objects because their properties are also not defined strictly by how many pixels they fill.

By arbitrary position, I mean any location within the document, NOT any rotation. I'm talking about horizontal and vertical lines. 

By selection, I mean a selection made with a marquee tool in a pixel layer. (There is more than one way to draw a line.) In the attached image, I made a selection with the Column Marquee Tool, and filled it with white on a black background (left line). Then I made another column selection, filled it, then dragged it a few pixels to the right (other line). You can see in the screen capture that the second line is still selected, but it's gotten wider and darker, the filled area now extends past the "selected" pixels.

So it looks like it's not possible to be precise with either vector or pixel objects. I understand why this is the case with vector objects, but a pixel is a pixel. A selected area of pixels should NOT change its appearance or size as it's dragged around the document.

Line Sample.jpg

Link to comment
Share on other sites

57 minutes ago, John-B said:

In the attached image, I made a selection with the Column Marquee Tool, and filled it with white on a black background (left line). Then I made another column selection, filled it, then dragged it a few pixels to the right (other line). You can see in the screen capture that the second line is still selected, but it's gotten wider and darker, the filled area now extends past the "selected" pixels.

If I understand what you want to do correctly, if you had enabled "Force Pixel Alignment" in the Snapping section of the main toolbar, dragging would have snapped the selection into whole pixel positions. (If the selection had not originally been pixel-aligned then it would have been necessary to disable "Move By Whole Pixels" but since the filled column selection is pixel-aligned that isn't necessary here.)

That attached force pixel alignment example.afdesign includes the history so you can move the history slider back & forth to see what I did to get the pure white fills.

All 3 1.10.8, & all 3 V2.4.1 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7
Affinity Photo 
1.10.8; Affinity Designer 1.108; & all 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.