Resizing Images in C# - Bilinear Filter?

Started by
0 comments, last by Telamon 20 years ago
Hey, I''m writing a game in C# and I''m designing the user interface to look good at resolutions from 800x600 to 1600x1200. I use a lot of icons and pictures to make the interface look good, but I only want to save one copy of the images with the game resources, and resize them on the fly. I''m looking for a way to do high-quality image resizing (ie. Bilinear Resampling). Is there a standard function in C# or the Win32 API I can use to do this? Or do I have to write my own? If I were to write my own, what is the fastest way to blast a bunch of pixels to the screen using the GDI? Is there a function I can pass an array of pixel data to that will copy it all onto a device context? I remember back in my Visual Basic days using SetPixel, but turning pixels on one at a time is really slow since each call locks and unlocks the GDI context. This seems like something that would be in the C# libraries... Can anyone point me in the right direction? Thanks a lot! ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Coding: http://www.stanford.edu/~jjshed/coding Miscellany: http://www.stanford.edu/~jjshed

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

Advertisement
The easy way:
Use the InterpolationMode property om the System.Drawing.Graphics class. For best quality scaling, use InterpolationMode.HighQualityBicubic.

The hard way:
Do it yourself. Get/SetPixel are still there but forget them. They are still way to slow. You need to use unsafe code. Use LockBits on the System.Drawing.Bitmap class to lock the bitmap data into system memory. Then get a pointer to the first byte of the bitmap data with the Scan0 property. Then just do your thing!

Remember that using unsafe code, you say "GC, no thanks!" etc. So you could easily screw up. Make sure you read up on unsafe code so you know whats going on.

This topic is closed to new replies.

Advertisement