Jump to content
  • Advertisement
Sign in to follow this  

[.net] OpenGL Tao & PictureBox Oddness

This topic is 4708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been having some problems saving images from a picturebox that OpenGL renders to via Tao. Here is the code:

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
            Dim pic_g As Graphics = PictureBox1.CreateGraphics
            Dim mybitmap As New Bitmap(PictureBox1.Width, PictureBox1.Height, pic_g)
            Dim bmp_g As Graphics = Graphics.FromImage(mybitmap)

            Dim pichdc As IntPtr
            Dim bmphdc As IntPtr

            pichdc = pic_g.GetHdc
            bmphdc = bmp_g.GetHdc

            BitBlt(bmphdc, 0, 0, mybitmap.Width, mybitmap.Height, _
                   pichdc, 0, 0, SRC_COPY)

            PictureBox2.Image = mybitmap

        End Sub

OK, here is the weirdness: bitblt indeed copies the image to mybitmap from picturebox1, because when I set picturebox2.image to mybitmap, it works. There is data there. But when I invoke picturebox2.image.save() or mybitmap.save(), it saves a black bitmap - all the color data goes bye-bye. Is there something I'm missing here? What is happening to the color data?

Share this post

Link to post
Share on other sites
OK, here is exactly what I am trying to accomplish:

I am taking data in through the parallel port. This data is then processed and displayed using Tao. The image is correctly being drawn to a PictureBox on a Windows form. When the user clicks the image, it is supposed to save it.

However, there is a problem. The Image member in the PictureBox object isn't getting the data. Somehow, OpenGL is rendering to some internal private member in my PictureBox that I can't get to.

For example...


...simply won't work. The Image member is set to 'Nothing', and the program throws. So to get at the image, I have decided to use the GDI function bitblt(). This seems to work when I transfer the image to a bitmap, then transfer that to another picturebox using...

PictureBox2.Image = mybitmap

I didn't need PictureBox2...it was just to check that the image was being transferred. The bitmap was saving totally black images, so I was checking to see if the image data was there with different PictureBoxes - and it is.

Anyway, when I go to save either the temporary bitmap OR PictureBox2.Image, I get a completely black bitmap. I have tried just about every way I can think of to get around this problem, but since I am new to the .NET way of doing things, I'm not sure.

Anyway, I hope that clarifies my problem.

Share this post

Link to post
Share on other sites
I give up. I just looked at the hex dump for the images I am getting. They are really corrupted. I am just going to bite the bullet and find another way.

Share this post

Link to post
Share on other sites
Solved it.

If anyone has a similar problem: Don't try to save in the same sub from the object that has the hRC, because there are pipelining issues (that's my guess), and you are likely to get the data only after gl.glClear() erases the data.

It is much better to use bitblt() to copy to a bitmap, then invoke that bitmap's Save method in a different sub.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!