Structure MonImage Public myImage As Image Public myPicture As PictureBox Private ImageWidth As Long Private ImageHeight As Long Private nbBlocsLargeur As Long Private nbBlocsHauteur As Long Private BlocWidth As Long 'x Private BlocHeight As Long 'y Sub DefinirUnBloc(ByVal bWidth As Long, ByVal bHeight As Long, ByVal NombreBlocsLargeur As Integer, ByVal NombreBlocsHauteur As Integer) BlocWidth = bWidth BlocHeight = bHeight nbBlocsLargeur = NombreBlocsLargeur nbBlocsHauteur = NombreBlocsHauteur End Sub Sub OpenImage(ByVal CheminFichierImage As String, ByVal DestPicture As PictureBox) myImage = Image.FromFile(CheminFichierImage) ImageWidth = myImage.Width ImageHeight = myImage.Height myPicture = DestPicture End Sub Sub CloseImage() myImage = Nothing End Sub Sub AfficherBloc(ByVal idbLargeur As Integer, ByVal idbHauteur As Integer) Dim nbBlocsUser As Integer = (idbLargeur * idbHauteur) Dim nbBlocsMax As Integer = (nbBlocsLargeur * nbBlocsHauteur) 'HEADER If nbBlocsUser <= 0 Or nbBlocsUser > nbBlocsMax Then MsgBox("Dépassement de bloc !" & vbNewLine & vbNewLine & _ "Largeur des blocs compris de 1 à " & Me.nbBlocsLargeur & vbNewLine & _ "Hauteur des blocs compris de 1 à " & Me.nbBlocsHauteur & vbNewLine & _ "Pour un total de " & nbBlocsMax & " blocs.", _ MsgBoxStyle.Exclamation, "Erreur: fonction AfficherBloc") Exit Sub End If 'LetsGo Dim myBitmap((nbBlocsLargeur - 1), (nbBlocsHauteur - 1)) As Bitmap Dim myGraphic As Graphics Dim myPoint As New PointF Dim i, j As Integer For i = 0 To (idbLargeur - 1) For j = 0 To (idbHauteur - 1) myBitmap(i, j) = New Bitmap(myImage, Me.BlocWidth, Me.BlocHeight) myGraphic = System.Drawing.Graphics.FromImage(myBitmap(i, j)) myPoint.X = BlocWidth * i myPoint.Y = BlocHeight * j myGraphic.DrawImage(myBitmap(i, j), 0, 0, New RectangleF(i, j, Me.BlocWidth, Me.BlocHeight), GraphicsUnit.Pixel) Next Next 'Affichage du bloc + myGraphic.Dispose() myPicture.Image = myBitmap(idbLargeur - 1, idbHauteur - 1) myGraphic = Nothing myBitmap = Nothing End Sub End Structure Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sI As String = "G:\BACKUP_PROGRAMMATION\VB.NET\Patchouz Fusion\Images\button.gif" Dim myImage As New MonImage With myImage .OpenImage(sI, Me.PictureBox2) .DefinirUnBloc(20, 21, 2, 3) .AfficherBloc(2, 3) .CloseImage() End With End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionmyBitmap = New Bitmap(CheminFichierImage)