views:

1329

answers:

2

I know it is possible, and a lot faster than using GDI+. However I haven't found any good example of using DirectX to resize an image and save it to disk. I have implemented this over and over in GDI+, thats not difficult. However GDI+ does not use any hardware acceleration, and I was hoping to get better performance by tapping into the graphics card.

+3  A: 

You can load the image as a texture, texture-map it onto a quad and draw that quad in any size on the screen. That will do the scaling. Afterwards you can grab the pixel-data from the screen, store it in a file or process it further.

It's easy. The basic texturing DirectX examples that come with the SDK can be adjusted to do just this.

However, it is slow. Not the rendering itself, but the transfer of pixel data from the screen to a memory buffer.

Imho it would be much simpler and faster to just write a little code that resizes an image using bilinear scaling from one buffer to another.

Nils Pipenbrinck
I was thinking it would be faster to use DirectX because of its use of hardware acceleration. I'm not interested in rendering it to the screen, only resizing it and saving it disk.
Greg Dean
The scaling itself would indeed be faster, but the preparation of the data for texture upload and the readback of the screen-pixels will outweight all performance benefits from using the hardware. It only makes sense to use DirectX if you scale the same image hundrets of times.
Nils Pipenbrinck
+1  A: 

Do you really need to use DirectX? GDI+ does the job well for resizing images. In DirectX, you don't really need to resize images, as most likely you'll be displaying your images as textures. Since textures can only applies on 3d object (triangles/polygons/mesh), the size of the 3d object and view port determines the actual image size displayed. If you need to scale your texture within the 3d object, just play the texture coordinate or matrix.

To manipute the texture, you can use alpha blending, masking and all sort of texture manipulation technique, if that's what you're looking for. To manipulate individual pixel like GDI+, I still think GDI+ is the way to do. DirectX was never mend to do image manipulation.

faulty
No I don't need to use DirectX, I am simply looking for a realistic alternative that might be faster than GDI+.
Greg Dean
If that's the case, there's plenty of library out there, like imagemagick(http://imagemagick.org/), there's more but I can't recall at the moment.
faulty