How to fix image with "low quality" in Listview

Asked

Viewed 95 times

1

Guys I was using the code below to create video thumbnail and show 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 Listview is a "bad" image, and the original has the quality of the original file. inserir a descrição da imagem aqui What I’d like to know is how I concert this.

  • Won’t be the method GetVideoThumbnail that is bringing a poor quality image? Or if you open the image manually it has good quality but only when you put in the ListView is that it becomes weak?

  • Exactly! Only when I put it in the listview it loses quality. Ex: In the image above on the left is the listview and looks like the last image of Paramount is bad, already on the right is the original version of the image that is played in the listview (the image that comes out of Getvideothumbnail).

  • In Picturebox the image is normal, but not in Listview.

1 answer

0


Try creating the image with the original color management:

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

If it still doesn’t look like 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 your image path by parameter.

Edit

I just noticed you’re using a ImageList to save the images before placing them on ListView. Try to do the following:

thumbnail.ColorDepth = ColorDepth.Depth32Bit

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

  • Both do not work. The first has the same result and the second returns all images in a light gray tone.

  • With the first option in Picturebox the image is normal, but not in listview.

  • In the second option change "Systemcolors.Control" to "Color.Transparent".

  • Images are now all black.

  • It’s hard... and if you remove that line from the Clear()?

  • When I changed I took this test too and everything went black. I resized the image to a size (256, 256) and showed the same image in Listview and Picturebox, but the image was good in the picturebox and bad in Listview. I had no idea what it might be?

  • Edit made in reply. The fact that you are using a ImageList could be the problem.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.