Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

resize image c#

    public static Image resizeImage(Image imgToResize, Size size)
    {
       return (Image)(new Bitmap(imgToResize, size));
    }

    yourImage = resizeImage(yourImage, new Size(50,50));
Comment

resize image c#


/// <summary>
/// Resize the image to the specified width and height.
/// </summary>
/// <param name="image">The image to resize.</param>
/// <param name="width">The width to resize to.</param>
/// <param name="height">The height to resize to.</param>
/// <returns>The resized image.</returns>
public static Bitmap ResizeImage(Image image, int width, int height)
{
    var destRect = new Rectangle(0, 0, width, height);
    var destImage = new Bitmap(width, height);

    destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

    using (var graphics = Graphics.FromImage(destImage))
    {
        graphics.CompositingMode = CompositingMode.SourceCopy;
        graphics.CompositingQuality = CompositingQuality.HighQuality;
        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
        graphics.SmoothingMode = SmoothingMode.HighQuality;
        graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

        using (var wrapMode = new ImageAttributes())
        {
            wrapMode.SetWrapMode(WrapMode.TileFlipXY);
            graphics.DrawImage(image, destRect, 0, 0, image.Width,image.Height, GraphicsUnit.Pixel, wrapMode);
        }
    }

    return destImage;
}

Comment

PREVIOUS NEXT
Code Example
Csharp :: unity c# get bool from another script 
Csharp :: bold caption latex 
Csharp :: c# unzip files 
Csharp :: Error inflating class android.support.constraint.ConstraintLayout 
Csharp :: c# mysql query 
Csharp :: how to find the mouse position unity 
Csharp :: c# read json file into object 
Csharp :: c# randomize a list 
Csharp :: move in the direction that player is facing unity 
Csharp :: how to reference scripts in other scenes unity 
Csharp :: generate random number c# 
Csharp :: unity string array 
Csharp :: c# right click event 
Csharp :: unity know when gameobject presed 
Csharp :: get the path of executable c# 
Csharp :: how to chnage the Scale propery of rect tranform unity 
Csharp :: unity convert mouse position to world position in editor mode 
Csharp :: get type of exception c# 
Csharp :: dynamics 365 update record c# 
Csharp :: {} is this used for code blcoks in c# 
Csharp :: c# print array 
Csharp :: byte to stream c# 
Csharp :: convert int array to string in C# 
Csharp :: how to draw over label C# 
Csharp :: gcd c# 
Csharp :: textbox only numbers c# 
Csharp :: .net hello world 
Csharp :: get item from icollection 
Csharp :: change array size in unity 
Csharp :: unity change material 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =