Click here to Skip to main content
6,292,426 members and growing! (10,678 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

FastPixel - A much faster alternative to Bitmap.SetPixel

By AndrewVos

Ever wanted something faster than SetPixel? Well you've found it.
VB, Windows, .NET, Visual Studio, Dev
Posted:15 Aug 2006
Views:36,637
Bookmarked:29 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
19 votes for this article.
Popularity: 4.86 Rating: 3.80 out of 5
1 vote, 5.3%
1
2 votes, 10.5%
2
1 vote, 5.3%
3
4 votes, 21.1%
4
11 votes, 57.9%
5

Sample Image - screenShot.jpg

Introduction

I have been working on some graphics code lately, and have been quite irritated with SetPixel and its performance overheads. There is an alternative though: Lock the bitmap and interact directly with with an array of bytes each representing R, G or B (and sometimes A, depending on whether it's an alpha bitmap or not).

Usage

Dim fp As New FastPixel(image)

fp.Lock()

fp.SetPixel(x, y, Color.Green)

fp.Unlock(True)

What I've learnt

  • Using Bitmap.Width or Bitmap.Height during an intense operation is very slow, because GdipGetImageWidth (or GdipGetImageHeight) is used to retrieve the value, and it isn't cached.
  • Using this class introduces speeds over 20 times faster than using SetPixel, on average.

Conclusion

Use the class!

Sorry about the length of this article, but there isn't much to explain. It's quite basic and I just wanted to get it out there so people could use it :>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

AndrewVos


Member

Occupation: Software Developer
Location: United Kingdom United Kingdom

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralVery usefull piece of code Pinmembernmajor0:26 22 Apr '08  
QuestionWould like to use Fast Pixel but...why do I get this error? Pinmemberled13:23 1 Apr '08  
GeneralGreat code... but there may be an issue PinmemberStimphy9:36 17 Jan '07  
GeneralCounterpart code in MFC/GDI... [modified] PinmemberJun Du3:28 6 Jan '07  
GeneralA C# code translation of this utility Pinmemberratamoa11:43 19 Oct '06  
GeneralRe: A C# code translation of this utility PinstaffChristian Graus11:55 19 Oct '06  
GeneralRe: A C# code translation of this utility PinmemberAndrewVos0:31 20 Oct '06  
GeneralRe: A C# code translation of this utility PinmemberAndrewVos0:40 20 Oct '06  
General1 bit conversion? Pinmemberbeckerben3:59 23 Aug '06  
GeneralRe: 1 bit conversion? [modified] PinmemberAlex@UEA1:04 24 Aug '06  
GeneralRe: 1 bit conversion? PinmemberAlex@UEA1:19 24 Aug '06  
GeneralRe: 1 bit conversion? Pinmemberbeckerben3:00 24 Aug '06  
GeneralRe: 1 bit conversion? PinmemberAlex@UEA4:43 24 Aug '06  
GeneralCorrection [modified] PinmemberAlex Fr4:55 16 Aug '06  
GeneralRe: Correction PinmemberAndrewVos7:01 16 Aug '06  
GeneralRe: Correction PinmemberAlex Fr7:32 16 Aug '06  
GeneralEasy of use Pinmembernorm .net0:17 16 Aug '06  
GeneralRe: Easy of use PinmemberAndrewVos1:25 16 Aug '06  
GeneralRe: Ease of use PinmemberDustin Metzgar3:46 16 Aug '06  
GeneralRe: Ease of use Pinmemberanomaly21:06 25 Oct '06  
GeneralRe: Easy of use Pinmemberaxelriet1:46 16 Aug '06  
GeneralRe: Easy of use Pinmembernorm .net1:54 16 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Aug 2006
Editor:
Copyright 2006 by AndrewVos
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project