Go Back   TechArena Community > Software > Windows Software
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-07-2011
Member
 
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?
Reply With Quote
  #2  
Old 26-07-2011
Member
 
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
Reply With Quote
  #3  
Old 26-07-2011
Member
 
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.
Reply With Quote
  #4  
Old 26-07-2011
Member
 
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
Reply With Quote
  #5  
Old 26-07-2011
Member
 
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.

//globpic 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 globpic.height
    globpic.rgbsurface.pixel(0,x) = rgb(red,grn,blu)
    red=red+red_pct
    blu=blu+blu_pct
    grn=grn+grn_pct
  next
g.drawpicture globpic,0,0,g.width,g.height,0,0,1,globpic.height
Reply With Quote
  #6  
Old 26-07-2011
Member
 
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)
Reply With Quote
  #7  
Old 27-07-2011
Member
 
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)
Reply With Quote
Reply

  TechArena Community > Software > Windows Software
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 05:32 AM.