MHT file is a single file containing all resources related to a webpage. Unlike HTML files, they can be viewed offline even if any server-hosted image, theme, or other resources are involved. Such files are usually saved with .MHTML file extension. Sometimes, you might need to convert an MHT file to an image for previewing the contents as a thumbnail. In accordance with such requirements, this article covers how to convert an MHT or MHTML file to an image in JPG, PNG, and other image formats programmatically in C#.
- MHT to Image Conversion – C# API Installation
- Convert MHT to JPG Image in C#
- Convert MHT to PNG Image Programmatically in C#
MHT to Image Conversion – C# API Installation
Aspose.HTML for .NET API supports working with webpages in HTML, MHTML, and several other file formats. You can configure the API by downloading its DLL files from the New Releases section or with the NuGet installation command below:
PM> Install-Package Aspose.Html
Convert MHT or MHTML to JPG Image in C#
You can convert an MHT or MHTML file to a JPG image by following the steps below:
- Create an object of the ImageSaveOptions class.
- Set image format to JPG image.
- Convert the MHT or MHTML to JPG image with ConvertMHTML method.
The following code snippet shows how to convert an MHT or MHTML file to JPG image programmatically in C#:
Convert MHT or MHTML to PNG Image Programmatically in C#
You can convert an MHT or MHTML file to a PNG image with the following steps:
- Create an object of the ImageSaveOptions class and set the image format to PNG.
- Convert the MHT or MHTML to PNG image using ConvertMHTML method.
The code snippet below elaborates on how to convert an MHT or MHTML file to a PNG image programmatically in C#:
Explore Aspose.HTML for .NET API
You can check many other features of the API by visiting the documentation.
Get Free License
You can evaluate the API without any evaluation limitations by requesting a free temporary license.
Conclusion
In this article, you have understood how to convert an MHT or MHTML file to images in JPG or PNG formats programmatically in C#. Moreover, in case of any concerns, please reach out to us at the forum.