Simple Resize Bmp : Bitmap « 2D Graphics « C# / C Sharp






Simple Resize Bmp

        
/** 
 *
 * IEC16022Sharp DataMatrix bar code generation lib
 * (c) 2007 Fabrizio Accatino <fhtino@yahoo.com>
 * 
 *   Core components are based on IEC16022 by Adrian Kennard, Andrews & Arnold Ltd
 *   (C version currently maintained by Stefan Schmidt)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 */


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;


namespace IEC16022Sharp
{
    public static class DMImgUtility
    {
        /// <summary>
        /// ....
        /// </summary>
        public static Bitmap SimpleResizeBmp(Bitmap inBmp, int resizeFactor, int boderSize)
        {
            int drawAreaW = resizeFactor * inBmp.Width;
            int drawAreaH = resizeFactor * inBmp.Height;
            Bitmap outBmp = new Bitmap(drawAreaW + 2 * boderSize, drawAreaH + 2 * boderSize);
            Graphics g = Graphics.FromImage(outBmp);

            // Imposta parametri per il resizing 
            // (Attenzione: senza PixelOffsetMode a HighQuality viene tagliato un pezzo dell'immagine)
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            // Sfondo bianco
            g.FillRectangle(Brushes.White, 0, 0, outBmp.Width, outBmp.Height);

            // Disegna immagine
            g.DrawImage(inBmp, new Rectangle(boderSize, boderSize, drawAreaW, drawAreaH), 0, 0, inBmp.Width, inBmp.Height, GraphicsUnit.Pixel);

            g.Dispose();
            return outBmp;
        }
    }
}

   
    
    
    
    
    
    
    
  








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
21.Scale Bitmap By Percent
22.Draws Bitmap in a cell within a DataGridView
23.Bitmap Image Utils
24.Bitmap Operations
25.Make Bitmap from UIElement
26.Creates a new bitmap from a specific region of another bitmap
27.Allows drawing fonts with borders and auto centers the font on a bitmap.
28.Create New Bitmap From Image
29.Create Thumbnail
30.Calculate the RBG projection
31.Make Thumb