Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Graphics Quality ???

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Graphics Quality ???

    I'm trying to get high quality lines drawn in my graphics.

    I'm using the following in C#:
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality ;

    I'm trying to find the JAVA equivalent.

    Through my research I found:
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G,
    RenderingHints.VALUE_ANTIALIAS_ON);

    but does not solve the problem.


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Graphics Quality ???

    I recommend posting a Short, Compileable, and correct example (SSCCE) to demonstrate what you mean. Setting the antialias rendering hint should help.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Graphics Quality - Interconnecting Line Segments ???

    Consider the attached image LINE1.jpg. You'll notice it has a diagonal line in the middle of the screen. The chart actually display's commodity prices but that is NOT what were talking about.

    My "main" program was originally developed in C# and I'm transferring it into JAVA. The original algorithm was designed to draw one line segment per candle. So the resulting line on the attached image is actually many interconnected line segments.

    You'll also notice however that the line appears jagged and un-smooth. I'm using:

    g2.setRenderingHint(
    RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);

    in my code but does not correct the problem. Continuing my research I'm also looking into the BasicStroke and line cap but that too does not correct the problem.

    LINE2.jpg shows what I want. Lines drawn that are 100% smooth. This was accomplished in JAVA but is actually one line and not many line segments that are interconnected as in LINE1.jpg

    My Question ...

    How can I make interconnected lines draw 100% smooth ???
    Attached Images Attached Images

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Graphics Quality - Interconnecting Line Segments ???

    I'm going to respond to my own post. I just modified my code so that it looks for the first and line segment only and connects the two. Here's my code:

    x = screen_left;

    // find right starting point
    for (int i = 0; i < bars_per_window - bars_removed - 1; i++)
    {
    x += bar_width;
    }

    float left_x = Float.MAX_VALUE;
    float left_price = 0;
    float right_x = Float.MIN_VALUE;
    float right_price = 0;

    // draw candles
    for (int i = jScrollBar.getValue(); i >= 0; i--)
    {


    for (int i2 = 0; i2 < indicator.trendline.values.size(); i2++)
    {

    Indicator.Value value = (Indicator.Value)indicator.trendline.values.get(i2 );

    if (value.id == i)
    {

    float p1 = (float)price_to_screen(value.value, min_price, max_price, screen_top, screen_height);
    float p2 = (float)price_to_screen(value.value + indicator.trendline.inc, min_price, max_price, screen_top, screen_height);

    if (x < left_x)
    {
    left_x = x;
    left_price = p1;
    }

    if (x > right_x)
    {
    right_x = x;
    right_price = p2;
    }

    break;
    }
    }


    x -= bar_width;

    if (Math.ceil(x) < screen_left) break;
    }


    g2.draw(new Line2D.Float(left_x, left_price, right_x, right_price));

  5. #5
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Graphics Quality ???

    Please do not start new threads on the same topic you just started. I have merged your threads. And please wrap your code in the code tags to preserve formatting.

Similar Threads

  1. how to use graphics g
    By steel55677 in forum AWT / Java Swing
    Replies: 11
    Last Post: November 21st, 2011, 05:35 PM
  2. Graphics class NullPointerException Initialize Graphics Class??
    By bglueck in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 13th, 2011, 11:13 PM
  3. JButton with 2D Graphics help
    By mystikaljester in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 13th, 2010, 08:33 PM
  4. Help about Graphics
    By mamech in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 9th, 2010, 03:20 PM
  5. graphics in job?
    By SweetyStacey in forum The Cafe
    Replies: 10
    Last Post: May 3rd, 2010, 03:29 PM