Results 1 to 7 of 7

Thread: How to increase Graphic Draw performance?

  1. #1
    Join Date
    Jun 2011
    Posts
    77

    How to increase Graphic Draw performance?

    I have experienced that Cocoa is slower drawing graphics inside a CANVAS. For increasing the performance speed, I have optimized my code and I succeeded in getting some speed. Know I want to do some more optimization. Which code would be faster for me? Any other alternatives code for it will be appreciated?

  2. #2
    Join Date
    Jun 2009
    Posts
    1,518

    Re: How to increase Graphic Draw performance?

    Generally the below code will draw a smooth color fade in a canvas. According to me it will be the fastest. Just have a glance over it:
    Code:
    dim startcolor as color = &c828282
      dim endcolor as color =  &cFEFFFE
      For x As Integer = 0 to g.height step 5
        g.forecolor = rgb( endcolor.red - (endcolor.red-startcolor.red) *x/g.height, _
        endcolor.green - (endcolor.green-startcolor.green) *x/g.height, _
        endcolor.blue - (endcolor.blue-startcolor.blue) *x/g.height)
        g.DrawLine 0,x,g.width,x
        g.DrawLine 0,x+1,g.width,x+1
        g.DrawLine 0,x+2,g.width,x+2
        g.DrawLine 0,x+3,g.width,x+3
        g.DrawLine 0,x+4,g.width,x+4
      next

  3. #3
    Join Date
    Nov 2008
    Posts
    1,514

    Re: How to increase Graphic Draw performance?

    As far as I am concerned the code to increase the performance of the graphic will be:
    Code:
    dim startcolor as color = &c828282
      dim endcolor as color =  &cFEFFFE
      For x As Integer= 0 to g.height
        g.forecolor = rgb( endcolor.red - (endcolor.red-startcolor.red) *x/g.height, _
        endcolor.green - (endcolor.green-startcolor.green) *x/g.height, _
        endcolor.blue - (endcolor.blue-startcolor.blue) *x/g.height)
        g.DrawLine 0,x,g.width,x
      next
    It will calculate the fore color for every five lines at a time.

  4. #4
    Join Date
    Mar 2009
    Posts
    1,360

    Re: How to increase Graphic Draw performance?

    If you ask me the above code will only change color every 5 lines, which may be good for the application but its not complete. The method that I am sharing with you will do 100% gradient transition for you.
    Code:
    dim startcolor as color = &c828282
      dim endcolor as color =  &cFEFFFE
      dim x as integer
      dim red as single
      dim grn as single
      dim blu as single
      dim red_pct as single
      dim grn_pct as single
      dim blu_pct as single
      red=endcolor.red
      grn=endcolor.Green
      blu=endcolor.blue
      red_pct=(startcolor.red-red)/g.height
      grn_pct=(startcolor.Green-grn)/g.Height
      blu_pct=(startcolor.Blue-blu)/g.height
      
      For x = 0 to g.height
        g.forecolor = rgb(red,grn,blu)
        g.DrawLine 0,x,g.width,x
        red=red+red_pct
        blu=blu+blu_pct
        grn=grn+grn_pct
      next

  5. #5
    Join Date
    Nov 2008
    Posts
    1,259

    Re: How to increase Graphic Draw performance?

    If you create a tiny picture and spread it using draw picture, you will gain speed. Always try to have ready- made picture of correct height including one pixel wide. This will save your time to create a picture in every paint event. Use Dave’s code and instead of a drawline, set the picture to 1 pixel wide.

    //glo***c is a property of the window, type picture, already created
    Code:
    dim startcolor as color = &c828282
      dim endcolor as color =  &cFEFFFE
      dim x as integer
      dim red as single
      dim grn as single
      dim blu as single
      dim red_pct as single
      dim grn_pct as single
      dim blu_pct as single
      red=endcolor.red
      grn=endcolor.Green
      blu=endcolor.blue
      red_pct=(startcolor.red-red)/g.height
      grn_pct=(startcolor.Green-grn)/g.Height
      blu_pct=(startcolor.Blue-blu)/g.height
      
      For x = 0 to glo***c.height
        glo***c.rgbsurface.pixel(0,x) = rgb(red,grn,blu)
        red=red+red_pct
        blu=blu+blu_pct
        grn=grn+grn_pct
      next
    g.drawpicture glo***c,0,0,g.width,g.height,0,0,1,glo***c.height

  6. #6
    Join Date
    Nov 2008
    Posts
    1,185

    Re: How to increase Graphic Draw performance?

    I agree with the idea that drawing a ready- made picture will especially increase the speed. The below I have mentioned the test code that I have personally used. It will do 200 iterations to get a delegate comparison.

    Ready made picture 16 ticks

    Code:
     dim z as integer
      dim t1 as integer
      dim t2 as integer
      
      dim g as graphics
      g = self.Graphics
      
      //have a picture already created.
      //this one is plain green, but it could be gradient filled
      dim p as new picture(1,self.height,32)
      p.Graphics.forecolor = &c328746
      p.Graphics.FillRect 0,0,1,p.height
      
      //here we go
      t1 = ticks
      for z = 1 to 200
        self.Graphics.DrawPicture p,0,0,self.width,self.height,0,0,p.width,p.height
      next
      t2 = ticks
      msgbox cstr(t2-t1)

  7. #7
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to increase Graphic Draw performance?

    If you are interested in further advanced optimization that is drawline version for 255 ticks instead of 16 ticks that use the below code:

    Code:
     dim z as integer
      dim t1 as integer
      dim t2 as integer
      dim x as integer
      dim g as graphics
      t1 = ticks
      
      
      dim startcolor as color = &c828282
      dim endcolor as color =  &cFEFFFE
      g = self.Graphics
      
      for z = 1 to 200
        For x =0 to g.height step 5
          g.forecolor = rgb( endcolor.red - (endcolor.red-startcolor.red) *x/g.height, _
          endcolor.green - (endcolor.green-startcolor.green) *x/g.height, _
          endcolor.blue - (endcolor.blue-startcolor.blue) *x/g.height)
          g.DrawLine 0,x,g.width,x
          g.DrawLine 0,x+1,g.width,x+1
          g.DrawLine 0,x+2,g.width,x+2
          g.DrawLine 0,x+3,g.width,x+3
          g.DrawLine 0,x+4,g.width,x+4
        next
      next
      t2 = ticks
      
      msgbox cstr(t2-t1)

Similar Threads

  1. How to increase the performance of C++ programs
    By Rikin J in forum Software Development
    Replies: 2
    Last Post: 10-08-2013, 10:26 AM
  2. How can I increase graphic card performance?
    By Wouter in forum Monitor & Video Cards
    Replies: 9
    Last Post: 06-08-2010, 12:59 PM
  3. Does Raid 1 increase performance ?
    By xing in forum Overclocking & Computer Modification
    Replies: 4
    Last Post: 23-09-2009, 11:17 AM
  4. Increase Performance for your PC
    By Honorata in forum Overclocking & Computer Modification
    Replies: 4
    Last Post: 21-01-2009, 05:46 PM
  5. help needed to increase graphic memory
    By undertaker690 in forum Monitor & Video Cards
    Replies: 4
    Last Post: 20-12-2008, 05:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,473,768.99978 seconds with 17 queries