Clicky

I need to draw 3 short lines on iPhone 3GS with distance 1 pixel between them. The line width is also 1 pixel.
The best I can get is 3 horizontal lines - I have a small png-file with these 3 lines and draw this png on the context.
 
the-image.png (137 bytes)
the source image (image/png)

But the same trick does not work for 3 vertical lines I always receive a rectangle.
The result looks so:
 
result.png (1 KB)
the result (image/png)

Probably, it's something about anti-aliasing/subpixeling.
Can you propose a way to draw these 3 lines?

asked 10/24/2011 12:21

pgnatyuk's gravatar image

pgnatyuk ♦♦


6 Answers:
I've had problems in the past before with drawing 1 pixel lines and not being pixel perfect. There's most likely a better solution but I managed to bypass my problem by drawing 1 pixel wide/high rectangles instead of lines.
link

answered

Snapples's gravatar image

Snapples

I think I know what the problem is, please show the code that draws the image on the context.
link

answered 2011-10-24 at 13:22:02

satsumo's gravatar image

satsumo

Thank you, guys.
The code is in Objective-C. So does it make sense to show it here?

What I have now perfect if I'll talk only about the images - the png-files. I prepare a png-file and the image looks exactly as I need - very sharp, very contrast.

The problem begins when I try to show this image on the screen.

Right now I found a way to "copy" the prepared image to the screen and almost don't loose the quality.

If you need an additional explanation, a source code to see here, in this thread, please let me know.
link

answered 2011-10-24 at 13:23:41

pgnatyuk's gravatar image

pgnatyuk

I see no reason why showing Objective-C is different to showing any other language?  Lots of people use Objective-C.  Anyway, I'm thinking that it's not about aliasing, however it depends what the code does.
link

answered 2011-10-25 at 00:39:52

satsumo's gravatar image

satsumo

The code does nothing:
1) load a png-file with the image  
2) draw it on an internal context; rotate this image and draw on this context;
3) then, I take UIImage from this context and this UIImage is shown in UIView via the layer.

It's not one function and so it's not an easy task to post the code. Which part is interesting?
For example, the following code put the image to an UIView:
[[[self viewTarget] layer] setContents:(id)[theImage CGImage]];

Here is the code that rotates an image
UIImage* rotated = [[UIImage alloc] initWithCGImage:[image CGImage]
                                                      scale:1.0f
                                              orientation:counter];

To draw this image on a context I use drawAtPoint: function.
I create the context with UIGraphicsBeginImageContextWithOptions.
I use simple [UIImage imageNamed:theImageName] to load the png-files.

link

answered 2011-10-25 at 04:09:08

pgnatyuk's gravatar image

pgnatyuk

Solved in the way described in the comment

link

answered 2011-10-25 at 05:26:05

pgnatyuk's gravatar image

pgnatyuk

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 10/24/2011 12:21

Seen: 445 times

Last updated: 10/30/2011 09:17