Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Code: Resize Photo with Windows, Resize

 

Task:

A small easy Windows C # code to downsize a photo or image to a smaller size

 

Subject: Windows Forms, C #. Also works in .NET Core code, Resize format

Bitmap source_Bitmap = new Bitmap(input_Image_Path);

Image outImage = new Bitmap(source_Bitmap, 100, 100);

 

Complete code example.

Here is a photo reduced. The photo is reduced to a maximum edge length.

public static void load_Photo_compressed_to_Clipboard(string input_Image_Path, int setLength)

{

    //---------------< Image_resize() >---------------

    Bitmap source_Bitmap = new Bitmap(input_Image_Path);

 

    double dblWidth_origial = source_Bitmap.Width;

    double dblHeigth_origial = source_Bitmap.Height;

 

    //< check orientation >

    bool IsOrientation_Horizontal = (dblWidth_origial > dblHeigth_origial) ? true : false;

    //</ check orientation >

 

    int new_Height = 0;

    int new_Width = 0;

    double zoom_factor = 1;

    if (IsOrientation_Horizontal == true)

    {

        new_Width = setLength;

        zoom_factor = new_Width / dblWidth_origial;

        new_Height = (int)(dblHeigth_origial * zoom_factor);

    }

    else

    {

        new_Height = setLength;

        zoom_factor = new_Height / dblHeigth_origial;

        new_Width = (int)(dblWidth_origial * zoom_factor);

    }

 

    Image outImage = new Bitmap(source_Bitmap, new_Width, new_Height);

    var t = new Thread((ThreadStart)(() =>

    {

        Clipboard.SetImage(outImage);

    }));

    t.SetApartmentState(ApartmentState.STA);

    t.Start();

    t.Join();

 

    //---------------</ Image_resize() >---------------

}

 

 

The following namespaces must be used

using System.Threading.Tasks;

using System.Threading;

 

using System.Drawing;           //*compress photo by windows

using System.Drawing.Imaging;   //*compress photo by windows

using System.Drawing.Drawing2D; //*compress quality

 

 

Mobile
»
Code: Resize Photo with Windows, Resize
»
C #: Show picture in WinForms
»
SMTP Error: Unable to read data from the transport connection
»
SMTPClient for sending with SSL and Authentication
»
SendMail Client in .Net Winform, WPF
»
Winforms: Connectionstring to the database
»
Net WinForms: Screen to Bitmap
»
WinForms: Code: Change the resolution of the monitor by app
»
C#, WinForms: Save and read settings

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de