Sign in to follow this  

texture.lock - c#

This topic is 4111 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

My overall goal is to get a rectangular portion of my texture and make another texture of it. I saw that texture.lock takes a rect as a parameter, but it keeps failing with an invalid call exception. Does anyone have an example of how to do this whether it be with this function or another? 1 ) Load a texture from file 2 ) Grab a rect from it 3 ) make a new texture from that rect

Share this post


Link to post
Share on other sites
the way I do it is probably not the best way. But I create a new texture, and a RenderToTexture object, then just draw a quad from your source texture onto it.


Texture t = new Texture(device, surfaceWidth, surfaceHeight, 1, Usage.None,Format.A8R8G8B8, Pool.Managed);

Direct3D.Surface surfaceTarget = t.GetSurfaceLevel(0);
renderToSurface = new RenderToSurface(device, SurfaceWidth, SurfaceHeight, Format.A8R8G8B8, false, DepthFormat.D16);

Viewport vp = new Viewport();

vp.X = 0;
vp.Y = 0;
vp.Width = surfaceWidth;
vp.Height = surfaceHeight;

renderToSurface.BeginScene(surfaceTarget, vp);

// draw quad here

renderToSurface.EndScene();

Share this post


Link to post
Share on other sites

This topic is 4111 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.

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