Convert image format from .bmp to other image formats in vb.net

How do you convert an image System.Drawing.Bitmapto another type of image? I tried CType, which failed, since I don't know the type for .png or .jpg. I can not find it anywhere on Google.

What is the most effective way to do this while keeping the image quality as high as possible?

+5
source share
3 answers

The class system.Drawing.Bitmap class can handle the opening and saving of any bitmap image , including JPG, PNG, GIF, BMP, and others.

To save a file that has already opened in a different format, you can use the save method this way

MyImage.Save("ImageName.jpg",System.Drawing.Imaging.ImageFormat.Jpeg)

Bitmp , BMP, , .

+8
+2

VB.NET. #, .

Public Function ConvertImageType(Image As Bitmap, Format As 
    Drawing.Imaging.ImageFormat) As Byte()
        'Declare a new memory stream to write to
        Dim SaveStream As New IO.MemoryStream
        'Save the bitmap/image to the memory stream in the desired format
        Image.Save(SaveStream, Format)
        'Extract the file bytes from the memory stream
        Dim ConvertedImageBytes() As Byte = SaveStream.ToArray
        'Return bytes to caller
        Return ConvertedImageBytes
    End Function

/ : Jpeg, Png, Bmp, Ico, Gif, Emf, Exif, Tiff Wmf.

0

Source: https://habr.com/ru/post/1716994/


All Articles