Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / C# - Padding a bitmap

Author
Message
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 7th Feb 2006 08:31
in my program, the user selects an image, and it will be copied to a certain folder, but when it's copied, i want to RESIZE the image, so it's SQUARE. BUT i don't want to stretch the image, I only want to pad the sides



that's the code i'm using now, but it stretches the image go figure, any idea how i could do this?

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Feb 2006 12:37
I don't know C#, but I'll try to help. You'll either have to create a new image and save over the old one, or edit the BMP at byte level. Determine which dimension is smaller, then make it match the larger one. Then fill in the new space with whatever color.

I could do this in DBP farely easily if that would help?


Deadly Night Assassins
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 7th Feb 2006 12:40 Edited at: 7th Feb 2006 12:41
Something I rustled up.

Loads a jpg, creates 50% additional space to right and bottom (in other words, expands the canvas) - saves the result to completed.jpg

Change the position of image in the DrawImage call to position your image appropriately.




Edit: oops, got a useless device context there in previous version. Unused variable fixed

Current work in progress: Retro Remake of BRUCE LEE, by Datasoft (1984)
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 7th Feb 2006 20:44
awesome, thanks

finished code:


Login to post a reply

Server time is: 2025-06-15 12:23:12
Your offset time is: 2025-06-15 12:23:12