1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Dim I, L, H, NbrFic As Integer
Dim ApiError As Integer
Dim Ratio As Single
Dim MonImage As System.Drawing.Bitmap
Dim Panel1 As New Panel
Dim Picture1 As New PictureBox
Dim Counter As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Counter = My.Computer.FileSystem.GetFiles(Chemin)
NbrFic = Counter.Count
Application.DoEvents()
For Each ImageTrouvée In _
My.Computer.FileSystem.GetFiles(Chemin, _
FileIO.SearchOption.SearchTopLevelOnly, "*.jpg*")
MonImage = New System.Drawing.Bitmap(ImageTrouvée)
L = MonImage.Width
H = MonImage.Height
Ratio = H / L
If Ratio > 1 Then
Picture1.Width = 90 / Ratio
Picture1.Height = 90
Else
Picture1.Width = 90
Picture1.Height = 90 * Ratio
End If
Picture1.Top = (100 - Picture1.Height) / 2
Picture1.Left = (100 - Picture1.Width) / 2
Picture1.SizeMode = PictureBoxSizeMode.StretchImage
Picture1.Image = MonImage 'Là ça fonctionne bien mais l'image est trop volumineuse
'-------------------------------------------------------------------
'Je voudrais la remplacer par l'Api suivante ou une autre plus adéquate pour réduire le poids de l'image
ApiError = StretchBlt(Picture1.hDC, 0, 0, Picture1.Width, Picture1.Height, MonImage.hDC, 0, 0, MonImage.Width, MonImage.Height, SRCCOPY)
'-------------------------------------------------------------------
Panel1.Width = 100
Panel1.Height = 100
Panel1.BackColor = Color.White
Fond.Controls.Add(Panel1) 'Fond est un FlowLayoutPanel
Panel1.Controls.Add(Picture1)
AddHandler Picture1.Click, AddressOf PictureClique
AddHandler Picture1.LostFocus, AddressOf PictureLostFocus
AddHandler Picture1.GotFocus, AddressOf PictureGotFocus
Panel1 = New Panel
Picture1 = New PictureBox
I += 1
Application.DoEvents()
Next
End Sub |
Partager