![]() ImageConverter imgCon = new ImageConverter() ImageConverter class can be used to convert Image objects from one data type to another. Also here use a RawFormat property of Image parameter which returns the file format of the image. Here we use the using blocks which ensures that it calls Dispose() method after the using-block is over, even if the code throws an exception. Using (MemoryStream mStream = new MemoryStream())īoth MemoryStream and Image have a dispose method, make sure you are Disposing of them as this can cause MemoryLeaks. Since the object is in memory, it can easily be converted into a byte array with the ToArray function from the MemoryStream object. Here this save function applied on the MemoryStream object, while specifying an image format. ![]() ![]() The Image object has a save function which allows developers to save an image to a file in any image format supported by the. You can make this conversion in many ways, but here you can see the fastest and memory efficient conversion in two ways. It is useful in many scenarios because byte arrays can be easily compared, compressed, stored, or converted to other data types. ![]() In many situations you may forced to convert image to byte array. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |