How to fix "low quality" image in Listview

1

I was using the code below to create thumbnail video and display in a ListView:

Dim cont As Integer = 0
    Dim thumbnail As New ImageList With {.ImageSize = New Size(200, 200)}
    Dim caminho_saida As String = "C:\..."
    Dim caminho_thumb As String
    Dim name_arquivos As String
    Dim xx As Image

    For Each zz In FileIO.FileSystem.GetFiles(caminho_saida)
        My.Computer.FileSystem.DeleteFile(zz)
    Next


    FolderBrowserDialog1.ShowDialog()

    Try
        For Each caminho_videos In FileIO.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchAllSubDirectories, "*.mp4")
            name_arquivos = System.IO.Path.GetFileNameWithoutExtension(caminho_videos)
            caminho_thumb = caminho_saida + name_arquivos + ".png"

            Try
                Dim ffMpeg = New NReco.VideoConverter.FFMpegConverter()
                ffMpeg.GetVideoThumbnail(caminho_videos, caminho_thumb, 20)
            Catch ex As Exception
                MsgBox(caminho_videos)
            End Try

            Using str As Stream = File.OpenRead(caminho_thumb)
                xx = Image.FromStream(str)
                thumbnail.Images.Add(xx)
            End Using

            ListView1.LargeImageList = thumbnail
            ListView1.Items.Add(name_arquivos, cont)


            cont += 1
        Next
    Finally
    End Try

The problem is that the result in the ListView is a "bad" image, the original having the quality of the original file. What I would like and to know how I concert it.

    
asked by anonymous 31.08.2018 / 00:21

1 answer

0

Try to create the image with the original color management:

Dim imagem As Image = Image.FromFile(strImagem, True)

If it does not stay the way you want, implement the following method:

Private Function RetornaImagemComQualidade(ByVal strImagem As String) As Image
    Dim imagem As Image = Image.FromFile(strImagem, True)
    Dim objBitmapImagem As Bitmap = New Bitmap(imagem.Width, imagem.Height, PixelFormat.Format24bppRgb)

    objBitmapImagem.SetResolution(imagem.HorizontalResolution, imagem.VerticalResolution)

    Dim objGraphicsImagem As Graphics = Graphics.FromImage(objBitmapImagem)

    objGraphicsImagem.Clear(SystemColors.Control)
    objGraphicsImagem.CompositingQuality = CompositingQuality.HighQuality
    objGraphicsImagem.InterpolationMode = InterpolationMode.HighQualityBilinear
    objGraphicsImagem.SmoothingMode = SmoothingMode.HighQuality

    objGraphicsImagem.Dispose()

    Return objBitmapImagem
End Function

Passing the path of your image by parameter.

Edit

I only noticed now that you are using ImageList to save the images before placing them in ListView . Try the following:

thumbnail.ColorDepth = ColorDepth.Depth32Bit

Another solution is to not resize images in ImageList and keep them the same size, doing so only in ListView .

    
31.08.2018 / 17:54