Archived

This topic is now archived and is closed to further replies.

Resizing Images in C# - Bilinear Filter?

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites