5,663,486 members and growing! (18,916 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
Updated: 15 Aug 2006
Views: 28,832
Bookmarked: 25 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 4.74 Rating: 3.78 out of 5
1 vote, 5.6%
1
2 votes, 11.1%
2
1 vote, 5.6%
3
4 votes, 22.2%
4
10 votes, 55.6%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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



Occupation: Web Developer
Location: South Africa South Africa

Other popular VB.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralVery usefull piece of codemembernmajor0:26 22 Apr '08  
QuestionWould like to use Fast Pixel but...why do I get this error?memberled13:23 1 Apr '08  
GeneralGreat code... but there may be an issuememberStimphy9:36 17 Jan '07  
GeneralCounterpart code in MFC/GDI... [modified]memberJun Du3:28 6 Jan '07  
GeneralA C# code translation of this utilitymemberratamoa11:43 19 Oct '06  
GeneralRe: A C# code translation of this utilitystaffChristian Graus11:55 19 Oct '06  
GeneralRe: A C# code translation of this utilitymemberAndrewVos0:31 20 Oct '06  
GeneralRe: A C# code translation of this utilitymemberAndrewVos0:40 20 Oct '06  
General1 bit conversion?memberbeckerben3:59 23 Aug '06  
GeneralRe: 1 bit conversion? [modified]memberAlex@UEA1:04 24 Aug '06  
GeneralRe: 1 bit conversion?memberAlex@UEA1:19 24 Aug '06  
GeneralRe: 1 bit conversion?memberbeckerben3:00 24 Aug '06  
GeneralRe: 1 bit conversion?memberAlex@UEA4:43 24 Aug '06  
GeneralCorrection [modified]memberAlex Fr4:55 16 Aug '06  
GeneralRe: CorrectionmemberAndrewVos7:01 16 Aug '06  
GeneralRe: CorrectionmemberAlex Fr7:32 16 Aug '06  
GeneralEasy of usemembernorm .net0:17 16 Aug '06  
GeneralRe: Easy of usememberAndrewVos1:25 16 Aug '06  
GeneralRe: Ease of usememberDustin Metzgar3:46 16 Aug '06  
GeneralRe: Ease of usememberanomaly21:06 25 Oct '06  
GeneralRe: Easy of usememberaxelriet1:46 16 Aug '06  
GeneralRe: Easy of usemembernorm .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-2008
Web17 | Advertise on the Code Project