Draw 3 lines

Posted on 2011-10-24
Medium Priority
Last Modified: 2012-05-12
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 source imageBut the same trick does not work for 3 vertical lines I always receive a rectangle.
The result looks so:
 the resultProbably, it's something about anti-aliasing/subpixeling.
Can you propose a way to draw these 3 lines?
Question by:pgnatyuk
  • 3
  • 2

Expert Comment

ID: 37020645
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.
LVL 12

Expert Comment

ID: 37020661
I think I know what the problem is, please show the code that draws the image on the context.
LVL 33

Author Comment

ID: 37022886
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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 12

Expert Comment

ID: 37023678
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.
LVL 33

Accepted Solution

pgnatyuk earned 0 total points
ID: 37024001
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]

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.

LVL 33

Author Closing Comment

ID: 37055455
Solved in the way described in the comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question