Archived

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

LockRectangle in VB.NET Help

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

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 on other sites
Hi, I have a completely different solution. Try this:

Dim r,g,b,a as ByteDim 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 WhileSurface.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]

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.

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

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 9
• 23
• 9
• 32
• Forum Statistics

• Total Topics
632624
• Total Posts
3007505
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

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!