Advertisement Jump to content


This topic is now archived and is closed to further replies.


LockRectangle in VB.NET Help

This topic is 5343 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

Hello, I have a function in VB.NET to get the bits of a texture. This is my code so far: Function img_GetBits(ByVal Key As String) As Byte() Dim Bits() As Byte With Tex(Key).Texture With .LockRectangle(0, New Rectangle(0, 0, Tex(Key).width, Tex(Key).height), Direct3D.LockFlags.ReadOnly) ''TODO: Copy data to Bits array End With .UnlockRectangle(0) End With Return Bits End Function I have two problems: One is that the LockRectangle statement returns an error (I have tried just about every overload of LockRectangle). Also, once I get it working, how would I go about copying the data to my array? (My bit array should contain the R, G, B, and A values of each pixel) Thanks in advance.

Share this post

Link to post
Share on other sites
Hi, I have a completely different solution. Try this:

Dim r,g,b,a as Byte
Dim Surface as Surface = Texture.GetSurfaceLevel(0)
Dim g_Stream as GraphicStream = Surface.LockRectangle(New Rectangle(0, 0, width, height), 0)

While Not (g_Stream.Position >= height * (width*4))
End While


However, this is only working for a 32bit (ARGB) texture, but you can easily adjust it to 16bit.


[edited by - Christoph on June 1, 2004 6:35:15 AM]

Share this post

Link to post
Share on other sites
Strange, LockRectangle is still giving me an error

This is the message it always gives me:

An unhandled exception of type ''Microsoft.DirectX.Direct3D.InvalidCallException'' occurred in microsoft.directx.direct3d.dll

Additional information: Error in the application.

The additional information is very helpful

Is there sometihng I should do when I create the device so I can use LockRectangle? Maybe that''s what''s causing it?

Oh, and one more thing, how do you get that white box with your code in it? I''m new to these forums

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!