Sign in to follow this  
ed209

getting pixels in MDX vb.net

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
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
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
Take a look at the Texture.LockRectangle method. It has a paramater called pitch at the end which will output the pitch.

Dim oStream As Microsoft.DirectX.GraphicsStream = oTex.LockRectangle(0, System.Drawing.Rectangle.Empty, Microsoft.DirectX.Direct3D.LockFlags.Discard, lPitch) <----

Share this post


Link to post
Share on other sites
Quote:
Original post by Headkaze
Take a look at the Texture.LockRectangle method. It has a paramater called pitch at the end which will output the pitch.

Dim oStream As Microsoft.DirectX.GraphicsStream = oTex.LockRectangle(0, System.Drawing.Rectangle.Empty, Microsoft.DirectX.Direct3D.LockFlags.Discard, lPitch) <----


Yes, I know. But it still freezes when I use lpitch. I'm using textdetails.height for the height, is that right?


oof, I think I'll just switch to C#.

Thanks.

Share this post


Link to post
Share on other sites
Given the way these libraries are designed I would imagine you'll have much the same problem with C# as you're having with VB.NET. When using libraries like this the syntax is largely irrelevant and its the semantics that'll get you - you can code incorrectly in any language [wink]

Whilst I'd also recommend C# over VB.NET (I'm still a bitter and disillusioned VB6 old timer) but if you're familiar with VB.NET then you're best sticking it out and trying to debug this issue rather than try and solve it by switching language/platform! Cracking a nut with a sledge hammer maybe?

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this