0% found this document useful (0 votes)
32 views

tool - Nuget Pakage Manager - Console: PM Install-Package Imageprocessor

This C# program uses the ImageProcessor NuGet package to resize an input image file, rotate it 90 degrees, save it in JPG format with 70% quality, and output it to a new file. The program loads the bytes of an input PNG file into a memory stream, runs image processing operations on it using the ImageFactory class, and writes the processed image bytes to an output memory stream that is then saved as a JPG file.

Uploaded by

MartínNuñez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

tool - Nuget Pakage Manager - Console: PM Install-Package Imageprocessor

This C# program uses the ImageProcessor NuGet package to resize an input image file, rotate it 90 degrees, save it in JPG format with 70% quality, and output it to a new file. The program loads the bytes of an input PNG file into a memory stream, runs image processing operations on it using the ImageFactory class, and writes the processed image bytes to an output memory stream that is then saved as a JPG file.

Uploaded by

MartínNuñez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Sample Program for Image Processing in C# Using ASP .

NET

//Tool->Nuget Pakage Manager-> Console: PM> Install-Package ImageProcessor

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.IO;

using ImageProcessor;
using ImageProcessor.Imaging.Formats;
using System.Drawing;

namespace ASPNETImageProcessing
{
class Program
{
static void Main(string[] args)
{
//byte[] photoBytes = File.ReadAllBytes("Apollo11_Launch7.png");
byte[] photoBytes = File.ReadAllBytes("YellowCar.png");
// Format is automatically detected though can be changed.
ISupportedImageFormat format = new JpegFormat { Quality = 70 };
Size size = new Size(300, 0);
using (MemoryStream inStream = new MemoryStream(photoBytes))
{
using (MemoryStream outStream = new MemoryStream())
{
// Initialize the ImageFactory using the overload to preserve EXIF
metadata.
using (ImageFactory imageFactory = new ImageFactory(preserveExifData:
true))
{
// Load, resize, set the format and quality and save an image.
imageFactory.Load(inStream)
.Rotate(90)
.Resize(size)
.Format(format)
.Save(outStream);
}
// Do something with the stream.
using (FileStream file = new FileStream "outfile1.jpg",
FileMode.Create, FileAccess.Write))
{
outStream.WriteTo(file);
}
}
}
}

CIS 465 Multimedia Sunnie Chung


}
}

Input File: "YellowCar.png"

CIS 465 Multimedia Sunnie Chung


Output file: outfile1.jpg

CIS 465 Multimedia Sunnie Chung

You might also like