friendsterTalk - Friendster Forum

friendsterTalk - Friendster Forum

Welcome guest! Please Login or Register.

#1  2008-11-11 17:26:12

creamownedz
 active server protocol
creamownedz's display avatar
» FriendsterTalker
PsychoCoder
Class-S
Location: Ftalk & MCTF
Registered: 2008-03-22
Posts: 115
Last visit: Yesterday
Reputation: 7

Resize an image in C# [c#]

This is a snippet for resizing an image based on a percentage. If the user wants the image to be 75% of the original then pass the number 75


Instructions: Need references to System.Drawing, System.Drawing.Drawing2D, System.Drawing.Imaging Namespaces


Code:

//Namespace Reference
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

/// <summary>
/// method for resizing an image
/// </summary>
/// <param name="img">the image to resize</param>
/// <param name="percentage">Percentage of change (i.e for 105% of the original provide 105)</param>
/// <returns></returns>
public Image Resize(Image img, int percentage)
{
    //get the height and width of the image
    int originalW = img.Width;
    int originalH = img.Height;

    //get the new size based on the percentage change
    int resizedW = (int)(originalW * percentage);
    int resizedH = (int)(originalH * percentage);

    //create a new Bitmap the size of the new image
    Bitmap bmp = new Bitmap(resizedW, resizedH);
    //create a new graphic from the Bitmap
    Graphics graphic = Graphics.FromImage((Image)bmp);
    graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
    //draw the newly resized image
    graphic.DrawImage(img, 0, 0, resizedW, resizedH);
    //dispose and free up the resources
    graphic.Dispose();
    //return the image
    return (Image)bmp;
}

...Giving of reputation are highly appreciating for me...
Computers don't make errors what they do they do on purpose
...computer is my expertise...
....an addicted coder....
....don't ripp all my tutorials....

#2  2008-11-14 06:25:38

mG
 «QuEzO dE BoLa™»
mG's display avatar
» FriendsterElite
Rockstars
Location: LP city
Registered: 2008-04-02
Posts: 3530
Reputation: 68
Friendster

Re: Resize an image in C# [c#]

WoOoW Thanks for
ds sis or bro.. =):thumbsup:
gonna use it now.. :lol:


RocK eN RoLL is nOt a LifesTyLe, ItS A bLoodTypE.

Search Friendstertalk

Board footer

FriendsterTalk is not affiliated with Friendster.com
Copyright © 2002–2009 PunBB

[ 8 queries - 1.279 second ]

Pay Per Click Ads by pay per click advertising by Kontera

FriendsterTalk.com x

Welcome to FriendsterTalk! You'll need to login in order to fully use all the features and view all the sections of this site.

Please register if you're not yet a member. =)