getting pixels in MDX vb.net
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???
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.
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(); }}
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.
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++.
Forget it. I'll just work in C# or C++.
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
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]
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]
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.
[Edited by - ed209 on July 8, 2008 7:08:58 PM]
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]
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:
So it should be:
Dim lDataSize As Int32 = lHeight * lPitch
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement