Draw 3 lines

Posted on 2011-10-24
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
    LVL 2

    Expert Comment

    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

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

    Author Comment

    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.
    LVL 12

    Expert Comment

    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

    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

    Solved in the way described in the comment

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now