Convert Image to Byte Array in C#.NET

Example of Converting Image to Byte Array in C#.NET
Converting image to Byte Array in C# class is not difficult with this high-quality C#.NET Image Conversion Library. It is acknowledged by C# programmers in this industry. Many C# developers choose this C#.NET Image Conversion Library because it is easy to use and it is completely available in .NET development environments.
The main purpose of this page is to tell you how to convert image to Byte Array in C# applications with our C#.NET Image Conversion SDK. C# sample code for image conversion to Byte Array is provided on this page. This Image Conversion SDK also supports other image conversions in both C#.NET and Visual Basic .NET projects.
This C#.NET Image Conversion SDK is an easy-to-use tool and is compatible with the following project development environments:
  • Windows 2000, Windows XP, Windows Vista, Windows 7 and Windows Server 2000 / 2003 / 2008
  • Visual Studio 2005, Visual Studio 2008 & Visual Studio 2010
  • .NET Framework 2.0 and later versions
How to Convert Image to Byte Array in C#
Converting image to Byte Array is a quite easy job with our C#.NET Image Conversion Library. We provide a specific guide for converting image to Byte Array in C# class as below. You just need to follow these steps and copy the C# demo code here.
  • In the first place, you need to download the free trial version of C#.NET Image Conversion SDK and activate the Evaluation License.
  • Then, the related reference (Yiigo.Imaging.Net.dll library) should be added to the C#.NET project you newly established.
  • Next, as there are two methods of converting image to Byte Array, you can copy the following two C# demo codes as you like.
  • Finally, you may run your project to see the result.
First C# Demo Code
     using Yiigo.Imaging.Basic;
using Yiigo.Imaging.Basic.Core;
using Yiigo.Imaging.Basic.Codec;

public static byte[] GetByteArrayFromImage(YGImage image, BaseEncoder enc);
Second C# Demo Code
     using Yiigo.Imaging.Basic;
using Yiigo.Imaging.Basic.Core;
using Yiigo.Imaging.Basic.Codec;

namespace YG__Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string fileName = "c:/Sample.png";

YGImage reImage = YGFile.OpenImageFile(fileName);
byte[] bytes = YGFile.GetByteArrayFromImage(reImage, new PNGEncoder());

return bytes;

}
}
}
Byte Array Overview in C#.NET
Byte Array stores binary data. The data may be part of a data file, image file, compressed file, downloaded server response or many other files. With Byte Array, you will have an ideal representation of the data. The Byte Array type allows you to store low-level representations. It is useful when optimizing certain methods.
It is able to allocate a Byte Array on the managed heap in the C# language and measure the memory usage of the managed heap before and after this allocation occurs. You can read in a Byte Array from a file using the C# language.
Byte Array is commonly used in .NET applications. The ASP.NET Framework makes extensive use of Byte Array in its internal code and also in some public interfaces. Byte Array is frequently used by some websites to optimize server-side performance.
Other Supported Image Conversion in C#
Apart from converting image to Byte Array, our .NET Image Conversion SDK also supports converting image to Stream, PDF and Word in Visual C# class.
Convert Image to Stream: Our website provides a guide to help users convert image to Stream and convert Stream to image in C# class. There are also guides for converting image to Stream in VB.NET, ASP.NET web or WinForms applications. If you have a demand, please go to respective guide page.
Convert PDF to Image: Various image formats (such as PNG, JPEG, BMP, TIFF etc.) can be converted to PDF file with our powerful Image Conversion Library in C#.NET. Users can completely use C# sample offered online to convert image to PDF.
Convert Word to Image: With this advanced C#.NET Image Conversion Component, developers are able to convert image to Word in an easy way. Our component will detect document and image formats automatically and the conversion will be finished in a fast speed.
Products
Other Plugins
Image Viewer CoreBarcode PluginPDF Read & WriteTesseract OCR PluginForm Processing PluginJBIG2 CodecJPEG2000 CodecISIS ScannerTwain ScannerDICOM ReaderCAD Scanner