Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 14 of 14

Thread: Re: What is best way to port BitBlt GUI application? (plus Autoredraw)

  1. #1
    Rob Teixeira Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


    "Patrick Ireland" <ireland@airmail.net> wrote:
    >
    >I am porting a VB6 app that display a program generate bit map in a
    >picture box.
    >
    >With all the new graphics features, what is the best way to do it in
    >VB.NET
    >
    >In VB6 the essence of the algorithm is
    >
    >1) Generate bit pattern in memory array


    Create a BitMap object (no need for extra array)

    >2) Generate BITMAPINFO structure for bit pattern (2, 16, or 256 color)


    The constructor of the Bitmap object allows you to set these parameters.
    The bitmap object also has properties relating to the BITMAPINFO members.

    >3) CreateCompatibleDC - memory DC
    >4) SelectObject - link memory DC with BITMAPINFO
    >5) BitBlt - memory to picture box
    >6) DeleteDC


    Dim g As Graphics = PictureBox1.CreateGraphics()
    Dim bmp As Bitmap = New Bitmap(Width, Height, g)

    bmp.SetPixel(100, 100, Color.Blue) 'fill the "array" of pixels

    PictureBox1.Image = bmp
    g.Dispose()

    You can also use the methods of the g (graphics) object (before calling Dispose)
    to draw more complex shapes, and even use automatic smoothing/anti-aliasing.

    Also, by setting the Image property of the picturebox to a Bitmap object,
    you effectively have autoredraw.

    I don't recommend using the BitBlt API, since you'd have to drop to unsecure
    unmanaged code.

    PS: SetPixel is blazingly fast compared to the old PSet method. If you understand
    what PSet did, it's easy to see why.

    -Rob

  2. #2
    Cali LaFollett Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)

    Thanks Rob!

    I guess that clears up Dan's minor oversight huh (no offense to Dan of
    course!)? <g>

    Cal



  3. #3
    Rob Teixeira Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)



    I would hope there's no offense
    Dan is one of the people in this industry I respect the most. You'll also
    find that for the amount of stuff he knows, he's quite humble, and has no
    problem admitting when he's wrong (if he is).
    But I think that .NET is so huge, it's difficult to get a grasp of EVERYTHING
    in such a short period of time. I also think that intimate knowledge of what
    goes on under the hood sometimes works against you when you try to accomplish
    something in .NET by using the exact same method. In most cases, the framework
    way is much easier, but it does require a bit of shifting in your approach.

    -Rob

    "Cali LaFollett" <cali@no-spam-please-visionized.com> wrote:
    >Thanks Rob!
    >
    >I guess that clears up Dan's minor oversight huh (no offense to Dan of
    >course!)? <g>
    >
    >Cal
    >
    >



  4. #4
    Cali LaFollett Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)

    > I would hope there's no offense

    Towards Dan, never! <g> His books are normally right on the money and have
    helped me through several sticky situations!

    > Dan is one of the people in this industry I respect the most. You'll also
    > find that for the amount of stuff he knows, he's quite humble, and has no
    > problem admitting when he's wrong (if he is).


    Which doesn't seem to be very often! Which is a good thing considering he is
    a well read authority.

    > But I think that .NET is so huge, it's difficult to get a grasp of

    EVERYTHING
    > in such a short period of time. I also think that intimate knowledge of

    what
    > goes on under the hood sometimes works against you when you try to

    accomplish
    > something in .NET by using the exact same method. In most cases, the

    framework
    > way is much easier, but it does require a bit of shifting in your

    approach.

    I agree completely. This is the road block I am running into right now. The
    Framework is HUGE and is rather overwhelming at first. I try to take it from
    a stance of looking at it like I did the Borland VCL when I first started
    learning Delphi 11/2 years ago. It has seemed to help that many of the class
    names and methods are very similar but there are many differences as well.

    I doesn't help a whole lot that I only get just a few hours a week to
    concentrate on .NET and the Framework. I am stuck in VB6 land for the time
    being although that may change here REAL quick depending on if I can get
    COM/.NET interop working here at work.

    Thanks again for your help.

    Cal





  5. #5
    Larry Serflaten Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


    "Rob Teixeira" <RobTeixeira@@msn.com> wrote
    >
    > Dim g As Graphics = PictureBox1.CreateGraphics()
    > Dim bmp As Bitmap = New Bitmap(Width, Height, g)
    >
    > bmp.SetPixel(100, 100, Color.Blue) 'fill the "array" of pixels
    >
    > PictureBox1.Image = bmp
    > g.Dispose()
    >
    > You can also use the methods of the g (graphics) object (before calling Dispose)
    > to draw more complex shapes, and even use automatic smoothing/anti-aliasing.
    >
    > Also, by setting the Image property of the picturebox to a Bitmap object,
    > you effectively have autoredraw.


    Can you elaborate on these? A simple test does not work for me:

    Dim g As Graphics = PictureBox1.CreateGraphics()
    Dim bmp As Bitmap = New Bitmap(Width, Height, g)

    bmp.SetPixel(100, 100, Color.Blue) 'fill the "array" of pixels
    g.DrawLine(Pens.Black, 0, 0, 90, 100)
    PictureBox1.Image = bmp
    g.DrawLine(Pens.Red, 0, 0, 100, 90)
    g.Dispose()

    Neither the black or red line shows up, but the blue dot does.

    You've disposed of g, but not bmp, is that an oversight, or is their
    some reason behind that? Am I correct in assuming to achieve AutoRedraw,
    the bmp (bitmap) should be scoped to the module level so that it remains
    as long as the form does, or will the image property keep the bitmap
    'alive' even as I dispose of bmp?

    And lastly, where are you learning this stuff from? <g>

    Thanks!
    LFS




  6. #6
    Rob Teixeira Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


    "Larry Serflaten" <serflaten@usinternet.com> wrote:
    >
    >Can you elaborate on these? A simple test does not work for me:
    >
    > Dim g As Graphics = PictureBox1.CreateGraphics()
    > Dim bmp As Bitmap = New Bitmap(Width, Height, g)
    >
    > bmp.SetPixel(100, 100, Color.Blue) 'fill the "array" of pixels
    > g.DrawLine(Pens.Black, 0, 0, 90, 100)
    > PictureBox1.Image = bmp
    > g.DrawLine(Pens.Red, 0, 0, 100, 90)
    > g.Dispose()
    >
    >Neither the black or red line shows up, but the blue dot does.


    In this case, g paints on the context of the picture box. Since the image
    is being replaced by the bitmap, you'd have to create a graphics object for
    the bitmap to directly paint on the bitmap itself.

    In other words:

    Dim g2 As Graphics
    'After setting bitmap object:
    g2 = Graphics.FromImage(bmp)
    g2.DrawLine(Pens.Blue, 0, 0, 100, 100)
    g2.Dispose()

    >You've disposed of g, but not bmp, is that an oversight, or is their
    >some reason behind that?


    Once you set the Image to the Bitmap, you need the bitmap to remain. If you
    dispose, you'll get an error.
    I believe the Picturebox will Dispose it's Image automatically when it's
    done, so you shouldn't have to worry about it. (somebody might correct me
    on that)

    >Am I correct in assuming to achieve AutoRedraw,
    >the bmp (bitmap) should be scoped to the module level so that it remains
    >as long as the form does, or will the image property keep the bitmap
    >'alive' even as I dispose of bmp?


    The Image property is a valid reference for keeping the object 'alive'.

    >And lastly, where are you learning this stuff from? <g>


    Reading the docs, and pure trial and error

    >Thanks!
    >LFS


    You're welcome.

    -Rob

  7. #7
    Patrick Ireland Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


    Rob,

    I would rather not use SetPixel since I have as 2048 by 1024 bitonal
    image to display. That many calls is a real killer for response time.

    Pat


    "Rob Teixeira" <RobTeixeira@@msn.com> wrote:
    >
    >"Patrick Ireland" <ireland@airmail.net> wrote:
    >>
    >>I am porting a VB6 app that display a program generate bit map in a
    >>picture box.
    >>
    >>With all the new graphics features, what is the best way to do it in
    >>VB.NET
    >>
    >>In VB6 the essence of the algorithm is
    >>
    >>1) Generate bit pattern in memory array

    >
    >Create a BitMap object (no need for extra array)
    >
    >>2) Generate BITMAPINFO structure for bit pattern (2, 16, or 256 color)

    >
    >The constructor of the Bitmap object allows you to set these parameters.
    >The bitmap object also has properties relating to the BITMAPINFO members.
    >
    >>3) CreateCompatibleDC - memory DC
    >>4) SelectObject - link memory DC with BITMAPINFO
    >>5) BitBlt - memory to picture box
    >>6) DeleteDC

    >
    > Dim g As Graphics = PictureBox1.CreateGraphics()
    > Dim bmp As Bitmap = New Bitmap(Width, Height, g)
    >
    > bmp.SetPixel(100, 100, Color.Blue) 'fill the "array" of pixels
    >
    > PictureBox1.Image = bmp
    > g.Dispose()
    >
    >You can also use the methods of the g (graphics) object (before calling

    Dispose)
    >to draw more complex shapes, and even use automatic smoothing/anti-aliasing.
    >
    >Also, by setting the Image property of the picturebox to a Bitmap object,
    >you effectively have autoredraw.
    >
    >I don't recommend using the BitBlt API, since you'd have to drop to unsecure
    >unmanaged code.
    >
    >PS: SetPixel is blazingly fast compared to the old PSet method. If you understand
    >what PSet did, it's easy to see why.
    >
    >-Rob



  8. #8
    Rob Teixeira Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)



    Well, you mentioned nothing about how you created your bit pattern. Since
    you had an array (i think), i assumed you were manipulating the pixels.
    However, as i said earlier, you have the full power of the Graphics class
    methods at your disposal, including DrawImage, and DrawImageUnscaled (think
    of it as BitBlt and StretchBlt).

    -Rob

    "Patrick Ireland" <ireland@airmail.net> wrote:
    >
    >Rob,
    >
    >I would rather not use SetPixel since I have as 2048 by 1024 bitonal
    >image to display. That many calls is a real killer for response time.
    >
    >Pat
    >
    >



  9. #9
    Patrick Ireland Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


    Rob,

    Yes indeed, I generate the bit patterns into an array. If the image is
    bitonal then each bit is a pixel, if the image is grey scale then each
    byte is a pixel, obviously, 256 grey scale. The images are extractions
    from image files that contain lots of CCITT4, JPEG, JPEG2000 (wavelets),
    of any of the aforementioned wrapped in TIFF. Since they are extractions
    I can not use a file name. I use DLL's for the decompression and get back
    the byte array. I'll look into DrawImage and DrawImageUnscaled.

    Thanks

    "Rob Teixeira" <RobTeixeira@@msn.com> wrote:
    >
    >
    >Well, you mentioned nothing about how you created your bit pattern. Since
    >you had an array (i think), i assumed you were manipulating the pixels.
    >However, as i said earlier, you have the full power of the Graphics class
    >methods at your disposal, including DrawImage, and DrawImageUnscaled (think
    >of it as BitBlt and StretchBlt).
    >
    >-Rob
    >
    >"Patrick Ireland" <ireland@airmail.net> wrote:
    >>
    >>Rob,
    >>
    >>I would rather not use SetPixel since I have as 2048 by 1024 bitonal
    >>image to display. That many calls is a real killer for response time.
    >>
    >>Pat
    >>
    >>

    >



  10. #10
    Rob Teixeira Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)



    In that case, you can create a Bitmap object by using the constructor with
    the Stream.

    -Rob

    "Patrick Ireland" <ireland@airmail.net> wrote:
    >
    >Rob,
    >
    >Yes indeed, I generate the bit patterns into an array. If the image is
    >bitonal then each bit is a pixel, if the image is grey scale then each
    >byte is a pixel, obviously, 256 grey scale. The images are extractions
    >from image files that contain lots of CCITT4, JPEG, JPEG2000 (wavelets),
    >of any of the aforementioned wrapped in TIFF. Since they are extractions
    >I can not use a file name. I use DLL's for the decompression and get back
    >the byte array. I'll look into DrawImage and DrawImageUnscaled.
    >
    >Thanks
    >



  11. #11
    Patrick Ireland Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


    Rob,

    Does the use of the Stream with the Bitmap Object allow for applying different
    artifacting to the same base image, i.e., applying different
    Fourier transports to the same base image to determine the best solution?
    I made be confused as usual, too many mood altering drugs in the 60's and
    70's 8-), but I have the impression that Stream was designed for input from
    I/O devices.

    Pat


    "Rob Teixeira" <RobTeixeira@@msn.com> wrote:
    >
    >
    >In that case, you can create a Bitmap object by using the constructor with
    >the Stream.
    >
    >-Rob
    >
    >"Patrick Ireland" <ireland@airmail.net> wrote:
    >>
    >>Rob,
    >>
    >>Yes indeed, I generate the bit patterns into an array. If the image is
    >>bitonal then each bit is a pixel, if the image is grey scale then each
    >>byte is a pixel, obviously, 256 grey scale. The images are extractions
    >>from image files that contain lots of CCITT4, JPEG, JPEG2000 (wavelets),
    >>of any of the aforementioned wrapped in TIFF. Since they are extractions
    >>I can not use a file name. I use DLL's for the decompression and get back
    >>the byte array. I'll look into DrawImage and DrawImageUnscaled.
    >>
    >>Thanks
    >>

    >



  12. #12
    Zane Thomas Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)

    On 22 Oct 2001 14:41:57 -0700, "Patrick Ireland" <ireland@airmail.net>
    wrote:

    > but I have the impression that Stream was designed for input from
    >I/O devices.


    Stream is usefull for all kinds of things, I put a base64 encoding stream
    into mime/net - very handy, does encoding/decoding on-the-fly as messages
    are sent/received.


    --
    The nice thing about standards is that
    there are so many of them to choose from.

  13. #13
    Rob Teixeira Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)



    Like Zane said, Streams are useful for a bunch of reasons. In this case,
    if you are getting the image data as a byte array (as a result from an extraction
    or other tool), then you can wrap that byte array into a memory stream, and
    use the Bitmap object's constructor that takes a stream.

    -Rob

    "Patrick Ireland" <ireland@airmail.net> wrote:
    >
    >Rob,
    >
    >Does the use of the Stream with the Bitmap Object allow for applying different
    >artifacting to the same base image, i.e., applying different
    >Fourier transports to the same base image to determine the best solution?
    >I made be confused as usual, too many mood altering drugs in the 60's and
    >70's 8-), but I have the impression that Stream was designed for input from
    >I/O devices.
    >
    >Pat
    >



  14. #14
    Patrick Ireland Guest

    Re: What is best way to port BitBlt GUI application? (plus Autoredraw)


    Thanks Rob & Zane,

    A coding I will go,
    A coding I will go,
    Hi ho the merri-o
    A coding I will go 8-)

    Pat


    "Rob Teixeira" <RobTeixeira@@msn.com> wrote:
    >
    >
    >Like Zane said, Streams are useful for a bunch of reasons. In this case,
    >if you are getting the image data as a byte array (as a result from an extraction
    >or other tool), then you can wrap that byte array into a memory stream,

    and
    >use the Bitmap object's constructor that takes a stream.
    >
    >-Rob
    >
    >"Patrick Ireland" <ireland@airmail.net> wrote:
    >>
    >>Rob,
    >>
    >>Does the use of the Stream with the Bitmap Object allow for applying different
    >>artifacting to the same base image, i.e., applying different
    >>Fourier transports to the same base image to determine the best solution?
    >>I made be confused as usual, too many mood altering drugs in the 60's and
    >>70's 8-), but I have the impression that Stream was designed for input

    from
    >>I/O devices.
    >>
    >>Pat
    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center