Imports System
Imports System.Collections.Generic
Imports fatd_faturamento.ENTIDADE

Public Class frmGaleriaFotos

    Private imagens As List(Of Image)
    Private miniaturas As List(Of PictureBox)

    Public Sub New(entidadeFotoEvidencia As List(Of entidadeAgenciaVirtualFoto))


        InitializeComponent()

        imagens = New List(Of Image)
        GC.Collect()
        GC.WaitForPendingFinalizers()

        Dim converter As New ImageConverter()
        'Dim imagem As Image = Nothing
        For Each foto As entidadeAgenciaVirtualFoto In entidadeFotoEvidencia
            'imagem = DirectCast(converter.ConvertFrom(foto.Base64), Image)
            imagens.Add(DirectCast(converter.ConvertFrom(foto.Base64), Image))
        Next

        miniaturas = New List(Of PictureBox)()


        GC.Collect()
        GC.WaitForPendingFinalizers()

        For i As Integer = 0 To imagens.Count - 1
            Dim miniatura As Image = imagens(i).GetThumbnailImage(50, 50, Nothing, IntPtr.Zero)
            Dim pictureBox As New PictureBox()

            pictureBox.Image = miniatura
            pictureBox.Width = 50
            pictureBox.Height = 50
            pictureBox.SizeMode = PictureBoxSizeMode.Zoom
            pictureBox.Tag = i

            AddHandler pictureBox.Click, AddressOf Miniaturas_Click

            pnl_miniaturas.Controls.Add(pictureBox)
            miniaturas.Add(pictureBox)
        Next
    End Sub

    Private Sub Miniaturas_Click(sender As Object, e As EventArgs)
        Dim pictureBox As PictureBox = DirectCast(sender, PictureBox)
        Dim index As Integer = CInt(pictureBox.Tag)
        imgControlFoto.Image = imagens(index).GetThumbnailImage(300, 400, Nothing, IntPtr.Zero)
    End Sub

    Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) 
        pnl_miniaturas.VerticalScroll.Value = e.NewValue
    End Sub
End Class

