Scale Bitmap By Percent : Bitmap « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » BitmapScreenshots 
Scale Bitmap By Percent
 

//Octavalent Extension Methods
//http://sdfasdf.codeplex.com/
//Library of extension methods for .Net create by Octavalent (www.octavalent.nl)


#region

using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

#endregion

namespace System.Drawing.OctavalentExtensions
{
    public static class BitmapExtensions
    {
        public static Bitmap ScaleByPercent(this Bitmap imgPhoto, int Percent)
        {
            float nPercent = ((floatPercent/100);

            int sourceWidth = imgPhoto.Width;
            int sourceHeight = imgPhoto.Height;
            var destWidth = (int) (sourceWidth*nPercent);
            var destHeight = (int) (sourceHeight*nPercent);

            var bmPhoto = new Bitmap(destWidth, destHeight,
                                     PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
                                  imgPhoto.VerticalResolution);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;

            grPhoto.DrawImage(imgPhoto,
                              new Rectangle(00, destWidth, destHeight),
                              new Rectangle(00, sourceWidth, sourceHeight),
                              GraphicsUnit.Pixel);

            grPhoto.Dispose();
            return bmPhoto;
        }
    }
}

   
  
Related examples in the same category
1.Draw on an Bitmap
2.Resize the Bitmap using the lowest quality interpolation mode
3.Resize the Bitmap using the highest quality interpolation mode
4.Create Graphics object From Image
5.Bitmap.SetResolution
6.Bitmap property: Height, Physical Dimension, width, raw format and sizeBitmap property: Height, Physical Dimension, width, raw format and size
7.Create your own BitMapCreate your own BitMap
8.Draw shapes to the bitmap in memoryDraw shapes to the bitmap in memory
9.new Bitmap(bitmap, size)
10.Read Bitmap Size by using BinaryReader
11.Bitmap.HorizontalResolution
12.Use a color matrix to change the color properties of the image
13.Create a Bitmap image in memory and set its CompositingMode
14.Create a red color with an alpha component then draw a red circle to the bitmap in memory
15.Create a green color with an alpha component then draw a green rectangle to the bitmap in memory
16.write the pixel information to the console window
17.Double buffer with Bitmap
18.Draw an array of imagesDraw an array of images
19.Bit operation with PixelFormat.Alpha
20.PixelFormat.DontCare
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.