Page 1 of 2 12 LastLast
Results 1 to 40 of 54

Thread: FastPix: Rapid Pixel Processing for Dummies and Dudes

  1. #1

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    FastPix: easy Rapid Pixel Processing (LockBits wrapper)

    EDIT October 2013: FastPix code modified to handle the Byte Array correctly. See post #38 below.

    People are forever complaining about the slowness of GetPixel and SetPixel. They probably weren't designed for processing whole images (or if they were, they were designed very badly). DotNet has an answer to that, but it's not an easy one to get your head around: the Bitmap class methods LockBits and UnlockBits.

    The main idea of FastPix is to provide a substitute for GetPixel and SetPixel which seem to work about 10 to 15 times as fast as the original ones. But it has more to offer.

    There are plenty of examples on the web of classes that encapsulate LockBits/UnlockBits. The ones I have seen are often hampered because they try to deal with different bitmap formats. But as far as I can see nearly all the bitmaps we deal with are either 24 bits (digital photos, some drawing programs) or 32 bits (drawing programs with transparency). GDI+ converts 24 bit images internally to 32 bits anyway, so I have designed FastPix to work with 32 bits only. It makes the code simpler and opens up the possibility of processing bitmaps as Integer arrays, which are blindingly fast. FastPix includes a ConvertFormat method for converting bitmap pixel formats or you can use:
    vb.net Code:
    1. Dim img = Image.FromFile(filename)
    2. Dim bmp As New Bitmap(img)
    The bitmap New sub converts a loaded image (but not an image file) to 32 bits.

    To start using Fastpix, download the attached zip file and unzip it to a convenient folder. In Visual Studio, select Project/Add Existing Item... and import the unzipped .vb file into your project.

    Here is an example of how you use the FastPix GetPixel and SetPixel substitutes. Their format is the same as the ones in the Bitmap class:
    vb.net Code:
    1. Using fp as New FastPix(myBitmap)
    2.        Dim myColor As Color =  fp.GetPixel(x, y)
    3.        fp.SetPixel(x, y, Color.Orange)
    4.     End Using
    Always declare a FastPix object with a Using loop, or otherwise Dispose it as soon as you have finished with it. The UnLockBits is in the Dispose method, so you will not be able to see your resulting bitmap until Dispose has been called either implicitly (with End Using) or directly.

    FastPix also offers you the bitmap in the form of an Integer Array and its performance leaves even the Fastpix GetPixel/SetPixel in the dust. Here's an example of how you use it:
    vb.net Code:
    1. Using fp as New FastPix(myBitmap)
    2.            'Make a local reference to the array; it is roughly 4x as fast as direct references to fp.PixelArray:
    3.            Dim pixels as Integer() = fp.PixelArray
    4.  
    5.               For i as integer = 0 to pixels.Length - 1
    6.  
    7.                    'example: substitute a color
    8.                    if pixels(i) = Color.Red.ToArgb then pixels(i) = Color.Blue.ToArgb
    9.  
    10.                    'example: invert the color
    11.                    pixels(i) = pixels(i) XOR $HFFFFFF
    12.  
    13.                Next
    14.             End Using
    Note how the inversion is done using only a logical instruction and a bit mask. If you can restrict yourself to techniques like that and to integer arithmetic, and avoid all references to objects outside the Class, you can get fantastic performance. For example, inverting the colors of a 10 MP digital photo can be done over 100x as fast as with old-fashioned GetPixel and SetPixel (150x if you don't count the LockBits/UnlockBits overhead).

    Of course, many kinds of pixel processing require you to get at the A, R, G and B bytes of the pixel. You can extract those from an integer using the BitConverter.GetBytes method, but that would slow things down terribly. Instead, it is possible to extract the bytes with masks and logic/shift operations only. They are probably just as fast as integer arithmetic. Here is an example which fades a bitmap by leveling all the Alpha byte values to a maximum level:
    vb.net Code:
    1. Dim _alpha As Byte 'Level Alpha down to this value
    2.  
    3. Using fp as New FastPix(myBitmap)
    4.    Dim pixels as Integer() = fp.PixelArray
    5.    Dim px As Integer = pixels(j)
    6.    Dim pxAlpha As Integer = (px >> 24) And &HFF 'shift alpha byte to bottom end, clear rest
    7.    If pxAlpha > _alpha Then
    8.       pxAlpha = CInt(_alpha) << 24
    9.       pixels(j) = (px And &HFFFFFF) Or pxAlpha 'replace original alpha value
    10.    End If
    11. End Using

    If you don't like the look of that, FastPix also provides a Byte array to make byte operations a bit less intimidating. Possibly it's not as fast as the integer array version. The bytes are in the order B, G, R, A for each pixel. Here's another example of fading a bitmap. Note the extra parameter in the FastPix declaration:
    vb.net Code:
    1. Using fp As New FastPix(myBitmap, True)
    2.    Dim bytes As byte() = fp.ColorByteArray
    3.    'Modify the Alpha bytes to make the bitmap 50% transparent:
    4.     For i As Integer = 3 to bytes.Length - 1 Step 4    
    5.        bytes(i) = 127
    6.     Next
    7. End Using

    I hope you find it useful. Comments and criticism welcome. BB
    Attached Files Attached Files
    Last edited by boops boops; Dec 9th, 2014 at 09:18 AM. Reason: a few more typos spotted!

  2. #2
    Member
    Join Date
    Feb 2011
    Location
    Nairobi/Kenya
    Posts
    45

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Wow, your code looks very lean and effective. How do i apply it to my project so that it can help me sharpen the image using track bar.
    Please show me some coding!

  3. #3

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Thanks for the compliment. I may be able to help you improve the performance, but I won't have time today. I'll look at it in the weekend. BB

  4. #4

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    This is a great entry into the codebank boops, well done!

  5. #5
    New Member
    Join Date
    May 2011
    Posts
    1

    Smile Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Wow. Cant believe that this has so few replies. This is just pure epicness! As you said, the slowness of GetPixel and SetPixel has always annoyed me, this finally fixes this issue. Yay!

    Many for you sir!

  6. #6
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Code:
    Using fp as New FastPix(myBitmap)
    myBitmap = bitmap variable ?

  7. #7

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    @Schravendeel. Thanks for your compliments!
    @Moti. Yes, it just stand for the name of your own bitmap. Sorry it wasn't clear.
    @Everyone. New version coming soon!

    BB

  8. #8
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    testing report :
    form controls :
    picturebox : with image in it, streched
    button
    textbox

    code used with fast pix class :
    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim bm As Bitmap
            bm = PictureBox1.Image
            Using fp As New FastPix(bm)
                Dim myColor As Color = fp.GetPixel(20, 20)
                fp.SetPixel(20, 20, Color.Orange)
                TextBox1.Text = myColor.ToString
            End Using
        End Sub
    End Class
    a glitch fired up :

    A first chance exception of type 'System.FormatException' occurred in pixelTest1.exe

    in the class line (after the if line):

    If pFSize <> 32 OrElse bmp.PixelFormat = PixelFormat.Indexed Then
    Throw New FormatException _
    ("FastPix is designed to deal only with 32-bit pixel non-indexed formats. Your bitmap has " _
    & pFSize & "-bit pixels. You can convert it using FastPix.ConvertFormat.")
    Else

  9. #9

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Moti, it specifically tells you how to deal with the problem right in the error message.

  10. #10
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    only .bmp ?

  11. #11

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    The program tells you the exact call to use in order to (hopefully) remove the error.

  12. #12
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    please stop the guessing game

    this also glitches:
    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim bm As Bitmap
            bm = PictureBox1.Image
            Using fp As New FastPix(bm)
                FastPix.ConvertFormat(bm, Imaging.PixelFormat.Alpha)
                Dim myColor As Color = fp.GetPixel(20, 20)
                fp.SetPixel(20, 20, Color.Orange)
                TextBox1.Text = myColor.ToString
            End Using
    
        End Sub
    End Class

  13. #13

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    You don't seem to get it. I'm not guessing; I'm telling you exactly what you need to hear. You need to convert it before you actually use the image otherwise you'll throw the exception. You know the method to use to perform the conversion, just change where it's being called. It's not that hard.

  14. #14
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    this ? FastPix.ConvertFormat(bm, Imaging.PixelFormat.Alpha)
    where should it go ?

  15. #15

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Before the Using statement...

  16. #16
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Quote Originally Posted by formlesstree4 View Post
    Before the Using statement...
    A first chance exception of type 'System.ArgumentException' occurred in System.Drawing.dll

    at the situation

  17. #17

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    How is that my problem? That's an exception in System.Drawing.dll, not FastPixel. Try wrapping Try-Catch statements around it and see what you get. Don't get mad at the person that's hand-feeding you help and try using some common logic to fix a problem.

  18. #18
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    I am not mad at you you're cool the glitches are what got to me
    I"ll just hope senior boobs hook me up with a walkthrough
    Last edited by moti barski; May 22nd, 2011 at 06:22 PM.

  19. #19
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Quote Originally Posted by moti barski View Post
    I am not mad at you you're cool the glitches are what got to me
    I"ll just hope senior boobs hook me up with a walkthrough
    Download the attachment in the first post. The author "boops boops" included a couple of examples in the downloadable file that have be commented out.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  20. #20

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    See post #1 in this thread:
    Quote Originally Posted by boops boops View Post
    nearly all the bitmaps we deal with are either 24 bits (digital photos, some drawing programs) or 32 bits (drawing programs with transparency). GDI+ converts 24 bit images internally to 32 bits anyway, so I have designed FastPix to work with 32 bits only. It makes the code simpler and opens up the possibility of processing bitmaps as Integer arrays, which are blindingly fast. FastPix includes a ConvertFormat method for converting bitmap pixel formats.
    BB

  21. #21
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    senior convertFormat glitched, before that there was another glitch and
    walkthrough pliz

  22. #22
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Moti, I propose that you are the glitch.

    Imaging.PixelFormat.Alpha is not a pixel format it is a flag, there is not such thing as a bitmap with a format of Alpha.

    The ConvertFormat() format parameter is optional you do not need to pass it, if you do pass it use one of the formats that start with Format32bpp.

    You must convert the Bitmap before you pass it to the FastPix constructor not after.

    PictureBox1.Image must contain a valid GDI Bitmap.
    W o t . S i g

  23. #23
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    so, it is a fluke if a bitmap work with the class, thanks milk now I get it

  24. #24

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Edit: follow Milk's advice. The next version of FastPix will make it a bit easier to avoid that mistake. BB

  25. #25

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Quote Originally Posted by moti barski View Post
    so, it is a fluke if a bitmap work with the class, thanks milk now I get it
    No fluke; it's pretty much spelled out how to make it work.

  26. #26
    Banned
    Join Date
    Mar 2009
    Posts
    764

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    and if I had wheels I'd be a wagon

  27. #27

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Quote Originally Posted by moti barski View Post
    and if I had wheels I'd be a wagon
    How does that even relate to this situation? You're merely making an analogy that has no reference to the subject at hand. I'm sorry but it wouldn't take very long to work with the code and produce the desired effect you want.

  28. #28
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,406

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Hi:

    I had download your code but VB don't recognize fastpix...

    Type 'Fastpix' is not defined

    Any suggestion?

    Thanks

  29. #29

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    1. download the zip file
    2. unzip it to obtain FastPix.vb
    3. save the file wherever you like to keep your downloaded code.
    4. in Visual Studio, right-click on your project name
    5. select Add Existing Item
    6. browse to find the FastPix.vb file and select it
    7. now you can use Faspix in the project.

    BB

  30. #30
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,406

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Hi:

    Thanks for your answear...
    I have one doubt her.e..your code could adapt to rotate images or graphics?

  31. #31

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Quote Originally Posted by sacramento View Post
    Hi:

    Thanks for your answear...
    I have one doubt her.e..your code could adapt to rotate images or graphics?
    It could be used for that in theory, but I doubt if it would be worth the effort. The GDI+ plus methods for rotation (Bitmap.RotateFlip, Graphics.RotateTransform etc.) seem pretty efficient to me. I suppose they use the same Math methods as you would use yourself on an array of pixels.

    BB

  32. #32
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,406

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Hi:

    Ok...thanks

  33. #33
    New Member
    Join Date
    Jul 2012
    Posts
    2

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    I've been using a different method for about a year without fail. It doesn't involve marshalling anything.

    I write this from memory, please excuse me if it is incorrect..
    vb.net Code:
    1. Imports System.Drawing
    2. Imports System.Drawing.Imaging
    3. Imports System.Runtime.InteropServices
    4.  
    5. Public Class DirectBitmap
    6.    
    7.     Private Handle as GCHandle
    8.     Public Readonly Pixels() as Int32
    9.     Public Readonly Bitmap as Bitmap
    10.     Public Readonly Width as Integer
    11.     Public Readonly Height as Integer
    12.    
    13.     Public Sub New(NewWidth as Integer, NewHeight as Integer)
    14.         Dim Area as Integer
    15.         Width = NewWidth
    16.         Height = NewHeight
    17.         Area = Width * Height
    18.         Redim Pixels(Area - 1)
    19.         Handle = GCHandle.Alloc(Pixels, GCHandleType.Pinned)
    20.         Bitmap = New Bitmap(Width, Height, 4 * Width, PixelFormat.Format32bppPArgb, Handle.AddrOfPinnedObject)
    21.     End Sub
    22.    
    23.     Protected Overrides Sub Finalize()
    24.         Bitmap = Nothing
    25.         Handle.Free()
    26.         Handle = Nothing
    27.         Pixels = Nothing
    28.         MyBase.Finalize()
    29.     End Sub
    30. End Class

  34. #34

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Hi SaxxonPike,

    I compared the "pinned array" method with "lockbits" when I was developing FastPix. It appeared that the pixel processing speed was more or less identical for the two methods, but the instantiation time for the pinned array was much longer, regardless of the bitmap size. I was also uncertain whether the pinned array code might yield problems further down the line (compared to the well-tried lockbits) so I decided to leave it on the shelf.

    It's easy to make mistakes when comparing performance, so now (with more experience) I should take a new look at it. Maybe I could try the code you have posted instead of my own version, which was based on a CodeProject example. So thanks for posting it.

    Besides, the pinned array approach has significant advantages when you need to process the same bitmap over and over again. Unlike lockbits, you don't have to unlock the bitmap to get at the results so you only have to create the array once. There may also be some advantage to processing the pinned array in an Unsafe block in Csharp, but from what I have read I wouldn't expect it to make a spectacular difference.

    BB

  35. #35
    New Member
    Join Date
    Jul 2012
    Posts
    2

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Quote Originally Posted by boops boops View Post
    Hi SaxxonPike,

    I compared the "pinned array" method with "lockbits" when I was developing FastPix. It appeared that the pixel processing speed was more or less identical for the two methods, but the instantiation time for the pinned array was much longer, regardless of the bitmap size. I was also uncertain whether the pinned array code might yield problems further down the line (compared to the well-tried lockbits) so I decided to leave it on the shelf.
    My guess would be that the garbage collector has to make special provisions as it cannot do anything with a pinned object. It's really useful if it's something like a screen buffer that won't change for the duration of execution. I am currently using it for a game project and notice no significant slowdowns as a result of creating and disposing bitmaps created in this manner, but I haven't done performance testing extensively as you have.

    Doesn't seem like I'm able to edit the code, after throwing it into VB I realized that "Bitmap" was a class name being used as a variable. Whoops The code should work otherwise (if you originally try it, all pixels will have value 0- completely transparent).

    Quote Originally Posted by boops boops View Post
    There may also be some advantage to processing the pinned array in an Unsafe block in Csharp, but from what I have read I wouldn't expect it to make a spectacular difference.
    I thought about using the Unsafe block as I also work with C#; however, that might require special permissions for the end-user and a special configuration for the program. I'm not a big fan of this myself

  36. #36

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Quote Originally Posted by SaxxonPike View Post
    Doesn't seem like I'm able to edit the code, after throwing it into VB I realized that "Bitmap" was a class name being used as a variable. Whoops The code should work otherwise (if you originally try it, all pixels will have value 0- completely transparent).
    Try putting square brackets round the identifier [Bitmap]. BB

  37. #37
    New Member
    Join Date
    Feb 2013
    Posts
    5

    Re: FastPix: easy Rapid Pixel Processing (LockBits wrapper)

    HI

    How I can display the modified image ( should be shown as 50% transparent, while the pciture in PictureBox2 appear as same as source..i,e PictureBox1)
    Should I need to convert the colorbyte array to bmp..or something like that..?
    vb.net Code:
    1. PictureBox1.Image = New Bitmap("8.jpg") ' source image
    2.  
    3.         Dim b = New Bitmap("8.jpg")
    4.         FastPix.ConvertFormat(b, Imaging.PixelFormat.Format32bppArgb)
    5.  
    6.         Using fp As New FastPix(b, True)
    7.             Dim bytes As Byte() = fp.ColorByteArray
    8.             'Modify the Alpha bytes to make the bitmap 50% transparent:
    9.             For i As Integer = 0 To bytes.Length - 1 Step 4
    10.                 bytes(i) = 127
    11.             Next
    12.         End Using
    13.  
    14.         PictureBox2.Image = b ' altered image
    [/QUOTE]

  38. #38

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: FastPix: easy Rapid Pixel Processing (LockBits wrapper)

    Hi supray,

    You have discovered an error in FastPix. It seems I never tested the Byte array (ColorByteArray) properly. Thanks for that, and my apologies.

    Fortunately it wasn't hard to fix. What I had to do was to declare _UseByteArray at class level, and then test it in the Dispose sub so as to write the correct data to the bitmap.

    Code:
    'added at Class level
    Private _UseByteArray As Boolean
    
    'added in the New sub
    _UseByteArray = UseByteArray
    
    'changed in the Dispose sub, instead of only writing _PixelData back to the bitmap:
    If _UseByteArray Then
    	If _ByteData IsNot Nothing Then Marshal.Copy(_ByteData, 0, _bmpData.Scan0, _ByteData.Length)
    Else
    	If _PixelData IsNot Nothing Then Marshal.Copy(_PixelData, 0, _bmpData.Scan0, _PixelData.Length)
    End If
    There's no need to make these changes yourself. I've posted the corrected FastPix Class as a new attachment to Post #1, because it's easier for people to find there.

    There is something else. The bytes in the Btye array are not stored in ARGB order but the reverse BGRA. You have to realize this if you are using the Byte array. Fortunately, the the only change needed in the code is to correct the byte array example in the FastPix comments, as well line 9 of own your code. All that's needed is to change 0 to 3:
    Code:
    For i As Integer = 3 To bytes.Length -1 Step 4
    That will make sure only the A bytes are changed. Make this change, and use the new version of FastPix from post #1, and your code should work ok.

    BB

  39. #39
    New Member
    Join Date
    Feb 2013
    Posts
    5

    Re: FastPix: easy Rapid Pixel Processing (LockBits wrapper)

    Thank you so much. Indeed its now working great !!!
    Great job !!!

  40. #40
    New Member
    Join Date
    Feb 2013
    Posts
    5

    Re: FastPix: Rapid Pixel Processing for Dummies and Dudes

    Hi

    Something I dont understand well...its my inablity. I was trying to use its different feature.
    I wanted to change the pixel color at (x,y) in steps so that it will appear as a uniforn grid (x, y dotted mesh grid line drawn on image..).

    The following code does not work (gives error : out of bound of the array). Am I missing something ?
    vb.net Code:
    1. PictureBox1.Image = New Bitmap("8.jpg")
    2.  
    3.         Dim b = New Bitmap("8.jpg")
    4.         FastPix.ConvertFormat(b, Imaging.PixelFormat.Format32bppArgb)
    5.  
    6.         Using fp As New FastPix(b)
    7.  
    8.             Dim pixels As Integer() = fp.PixelArray
    9.  
    10.             For x As Integer = 0 To pixels.Length - 1 Step 200
    11.                 For y As Integer = 0 To pixels.Length - 1 Step 200
    12.  
    13.                     Dim myColor As Color = fp.GetPixel(x, y)
    14.                     fp.SetPixel(x, y, Color.Orange)
    15.                    
    16.                 Next
    17.             Next
    18.         End Using
    19.  
    20. PictureBox2.Image = b

    while the following code works but the dot in each row shifted so that it seems the lines are drawn diagonally and ofcourse only set of parallel line (diagonally)

    vb.net Code:
    1. PictureBox1.Image = New Bitmap("8.jpg")
    2.  
    3.         Dim b = New Bitmap("8.jpg")
    4.         FastPix.ConvertFormat(b, Imaging.PixelFormat.Format32bppArgb)
    5.  
    6.         Using fp As New FastPix(b)
    7.  
    8.             Dim pixels As Integer() = fp.PixelArray
    9.  
    10.             For x As Integer = 0 To pixels.Length - 1 Step 200
    11.  
    12.                 pixels(x) = Color.Blue.ToArgb()
    13.                    
    14.             Next
    15.         End Using
    16.  
    17. PictureBox2.Image = b

    does PixelArray retrun a array for each horizontal row of the image ?

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width