Skip to main content
gamedev.net
🔒 Locked

LockRectangle in VB.NET Help

Started by andy1 1 reply 600+ views
Original Post
andy1
andy1
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.
Christoph
Christoph
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))
b=g_Stream.ReadByte()
g=g_Stream.ReadByte()
r=g_Stream.ReadByte()
a=g_Stream.ReadByte()
End While

Surface.UnlockRectangle()


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

Greetz,
Chris

[edited by - Christoph on June 1, 2004 6:35:15 AM]
andy1
andy1
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.