Create bitmap from scratch or load from file using C#
Contents
[
Hide
]
Creating bitmap from scratch or loading from file using C# is a common requirement. Aspose.Drawing for .NET lets you create a bitmap from scratch or open from an existing file that can further be edited.
Create New Bitmap in C#
Creating a new image from scratch is easy using Aspose.Drawing for .NET API. The following C# example shows how to create a new drawing and draw an arc on it.
- Instantiate an object of Bitmap class
- Initialize an object of Graphics class from this bitmap
- Define a Pen object with desired parameters
- Use the DrawArc method of Graphics class object to draw an arc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
using System.Drawing; | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
Graphics graphics = Graphics.FromImage(bitmap); | |
Pen pen = new Pen(Color.Blue, 2); | |
graphics.DrawArc(pen, 0, 0, 700, 700, 0, 180); | |
bitmap.Save("DrawArc.png"); |
Load existing Image from File into Bitmap
You can also load an existing image from file and save it back to disc using the API as shown in the following C# code sample.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-.NET | |
// Load the image: | |
Bitmap bitmap = new Bitmap(RunExamples.GetDataDir() + @"Images\aspose_logo.png"); | |
// Save the image: | |
bitmap.Save(RunExamples.GetDataDir() + @"Images\LoadSave_out.png"); |