Jump to content
  • Advertisement
Sign in to follow this  
ed209

getting pixels in MDX vb.net

This topic is 3630 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 swear to god I have searched in every possible place and still can't find an example of getting x,y pixels off of a texture in mdx vb.net. Though, I found tons of examples for C#. Could someone please show me how this is done???

Share this post


Link to post
Share on other sites
Advertisement
As a vb.net programmer you should be able to understand the c# examples. The libraries are the same. If not, post the C# examples you found here, and I will help bridge the syntax.

Share this post


Link to post
Share on other sites

uint[,] data = (uint[,])texture.LockRectangle(0, LockFlags.None, _size.Width, _size.Height);

for (int i=0; i < _size.Width; i++)
{
for (int j=0; j < _size.Height; j++)
{
data[i,j] = (uint) Color.White.ToArgb();
}
}

Share this post


Link to post
Share on other sites
Do a search on Google for "c# to vb.net" there are several free online services that will convert code snippets from C# to VB.NET and vias versa.

Share this post


Link to post
Share on other sites
Error 1 Value of type 'Microsoft.DirectX.GraphicsStream' cannot be converted to 'UInteger'. C:\vb.net\directx\LoadTexture\Form1.vb 79 41 LoadTexture


Forget it. I'll just work in C# or C++.

Share this post


Link to post
Share on other sites
here is my code. I use UInt because thats what the C# code used.


Dim textdetails As SurfaceDescription
textdetails = pirateship.GetLevelDescription(0)

Dim rect As New Rectangle
rect.Width = textdetails.Width
rect.Height = textdetails.Height

Dim gs As GraphicsStream

Dim data(,) As System.UInt32 = CType(pirateship.LockRectangle(0, rect, LockFlags.None), System.UInt32(,))

Dim i As Integer
For i = 0 To textdetails.Width - 1 Step i + 1
Dim j As Integer
For j = 0 To textdetails.Height - 1 Step j + 1
data(i, j) = CType(Color.White.ToArgb(), System.UInt32)
Next
Next

Share this post


Link to post
Share on other sites
Ok, the lock rectangle method returns an object of graphicsStream. There's no conversion for graphicsStream to Uint(,).

So, I would advise doing the following:
Dim lPitch As Int32
Dim oStream As Microsoft.DirectX.GraphicsStream = oTex.LockRectangle(0, System.Drawing.Rectangle.Empty, Microsoft.DirectX.Direct3D.LockFlags.Discard, lPitch)
Dim lDataSize As Int32 = ((4 * lHeight) * lWidth) - 1
Dim yData(lDataSize) As Byte

lVal = oStream.Read(yData, 0, yData.Length)

'yData() now contains a linear array of bytes for the image

Edit: and when you're done, use oStream.Write.
Another Edit: just realized I had 32's in where height and width were supposed to be above. sorry for the confusion.

[Edited by - EnochDagor on July 8, 2008 3:11:18 PM]

Share this post


Link to post
Share on other sites
Thanks a lot!

But whenever I try to use oStream.Write(yData, 0, yData.Length) the program just freezes.

I'm pretty sure it has something to do with lDataSize.


Dim lDataSize As Int32 = (4 * textdetails.Height * textdetails.Width) -1


[Edited by - ed209 on July 8, 2008 7:08:58 PM]

Share this post


Link to post
Share on other sites
You will have to use the lPitch (aka stride) instead of width because a texture's pixel's may be aligned and so using lWidth will return the wrong size.

So it should be:

Dim lDataSize As Int32 = lHeight * lPitch

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!