Loading part of a Bitmap

Started by
5 comments, last by StratBoy61 17 years ago
Heya guys, Just wondering if someone can enlighten me of what method I should use to load a part of a bitmap image using Direct3D. Thanks Meldinoor
Advertisement
Hey,

Could you please be more specific ? What is it you want to do exactly ? Are you willing to transform part of a source bitmap into a Direct3D texture ? If so, you can still check a previous answer that is related to it.
Please let us know.
StratBoy61
Yeah, that's pretty much what I'm trying to do, except I'm writing it in C#. I thought there would be some simple function in Direct3D to load part of a bitmap, but I couldn't find it. Until now I've loaded textures using Direct3D.TextureLoader.FromFile but then I wanted to store several textures on the same bitmap file.
I'll try something similar to what you suggested in the other thread, but I'll be thankful for more ideas.
Quote:Original post by Meldinoor
Yeah, that's pretty much what I'm trying to do, except I'm writing it in C#. I thought there would be some simple function in Direct3D to load part of a bitmap, but I couldn't find it. Until now I've loaded textures using Direct3D.TextureLoader.FromFile but then I wanted to store several textures on the same bitmap file.
I'll try something similar to what you suggested in the other thread, but I'll be thankful for more ideas.


From an efficiency point of view, if you have several textures in a single bitmap it may be advantageous to load them all into one texture (if the size is feasible, which I believe these days is a texture about 2048x2048) and use texture co-ordinates when mapping different textures.

This means you can batch larger numbers of primitives since you do not need to keep changing the texture.

In terms of a simpler answer to your question, I know next to nothing about using C# with Direct3D, but if I were approaching this with C++ and Direct3D, I'd consider accessing the relevant surface of the texture, using the surface to get old of a GDI-style device context, using the GDI to load the bitmap and then using GDI calls to CopyRect bits of the source bitmap into your texture surface.

I've never tried that though so I could be rambling nonsense. The approach I've used for loading several bitmaps onto one texture, which is the opposite problem but in some ways similar, has been to lock the texture and directly write pixels from a DIB of the bitmap into the texture memory. If you have specified your pixel format, this is not too painful with C++, but again I can't speak for C#.

Lots of speculative ramblings there. I hope something in the above was of some use [smile].
This depends on what you want exactly. Do you want a new texture resource with just that sub image or do you just want to draw part of an image?
Quote:Original post by xgalaxy
This depends on what you want exactly. Do you want a new texture resource with just that sub image or do you just want to draw part of an image?


I want a new texture resource. I guess I could just copy the pixels off the bitmap that I want, but I wonder what methods others have used for this. Basically what I'm doing is animations for sprites in a 2D-Isometric game and I determined that loading a large bitmap once and using parts of it for each object's animation frames would be more efficient than repeatedly loading it into memory. Should I simply use for-loops to copy the pixels I want off the original resource?

Meldinoor
Are you in fact just willing to use sprites ? If so, you first need to load the whole bitmap and then, display only portions of it.

This topic is closed to new replies.

Advertisement