Click here to Skip to main content
15,867,141 members
Articles / Mobile Apps / Windows Mobile
Tip/Trick

Bitmap resize with .NET Compact Framework

Rate me:
Please Sign up or sign in to vote.
4.60/5 (8 votes)
15 Dec 2010CPOL 23.8K   5   2
Bitmap resize with .NET Compact Framework

Hello. I develop C# with the .NET Compact Framework.


The support of images in C# is very poor. Not only that transparency is not supported, I also found no way to resize images with C# CF (3.5).


I searched for a long time to resize Bitmaps and I also found no simple way to make an DLL invoke for it.


My challenge was to resize an Bitmap object.


Finally, I found a solution which is working:

public static Bitmap resizeBitmap(Bitmap original, int newX, int newY) {
    Rectangle recSrc = new Rectangle(0, 0, original.Width, original.Height);
    Rectangle recDest = new Rectangle(0, 0, newX, newY);
    Bitmap target = new Bitmap(newX, newY);
    Graphics g = Graphics.FromImage(target);
    g.DrawImage(original, recDest, recSrc, GraphicsUnit.Pixel);
    return target;
}

Hopefully it helps somebody of you, so I'm posting it here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
hjgode16-Oct-14 2:02
hjgode16-Oct-14 2:02 
GeneralReason for my vote of 3 Nothing new... Pin
GPUToaster™17-Nov-10 19:57
GPUToaster™17-Nov-10 19:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.