Structure MonImage Public myBitmap As Bitmap 'source file Public myPicture As PictureBox 'dest picbox 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) myBitmap = New Bitmap(CheminFichierImage) ImageWidth = myBitmap.Width ImageHeight = myBitmap.Height myPicture = DestPicture End Sub Sub CloseImage() myBitmap = 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 myBitmapClone((nbBlocsLargeur - 1), (nbBlocsHauteur - 1)) As Bitmap Dim myGraphic As Graphics Dim myPoint As New PointF Dim myRect As Rectangle Dim i, j As Integer For i = 0 To (idbLargeur - 1) For j = 0 To (idbHauteur - 1) myPoint.X = BlocWidth * i myPoint.Y = BlocHeight * j myRect = New Rectangle(myPoint.X, myPoint.Y, Me.BlocWidth, Me.BlocHeight) myBitmapClone(i, j) = myBitmap.Clone(myRect, myBitmap.PixelFormat) Next Next myPicture.Image = myBitmapClone(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(22, 23, 2, 3) .AfficherBloc(2, 3) .CloseImage() End With End Sub
Dim myDraw As System.Drawing.Graphics PictureBox1.InitialImage = New myDraw.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel)
Dim myDraw As System.Drawing.Graphics myDraw = PictureBox1.Image myDraw.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim a As System.Windows.Forms.PaintEventArgs a.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel)
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sI As String = "G:\button.gif" Dim myImage As System.Drawing.Image = System.Drawing.Image.FromFile(sI) Dim srcRect As New System.Drawing.Rectangle(0, 0, 44, 69) Dim i As Integer Dim dstRect(2, 1) As System.Drawing.Rectangle Dim UnBouton As System.Drawing.Rectangle Dim posBouton As System.Drawing.Point UnBouton.Width 20 : UnBouton.Height 21 posBouton.X 0 : posBouton.Y 0 '2 = 0 inactif, 1 mouveenter, 2 mouseclick '1 = 0 minimiz, 1 close For i = 0 To 2 dstRect(i, 0) = New System.Drawing.Rectangle(posBouton.X, posBouton.Y, UnBouton.Width, UnBouton.Height) dstRect(i, 1) = New System.Drawing.Rectangle(posBouton.X + UnBouton.Width, posBouton.Y, UnBouton.Width, UnBouton.Height) posBouton.Y = posBouton.Y + UnBouton.Height Next Dim myBitmap As New System.Drawing.Bitmap(myImage, UnBouton.Width, UnBouton.Height) Dim myGraphic As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(myBitmap) myGraphic.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel) End Sub
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 System.Drawing.Image = System.Drawing.Image.FromFile(sI) Dim srcRect As New System.Drawing.Rectangle(0, 0, 44, 69) Dim i, j As Integer Dim dstRect(2, 1) As System.Drawing.Rectangle Dim myBitmap(5) As System.Drawing.Bitmap Dim myGraphic As System.Drawing.Graphics Dim UnBouton As System.Drawing.Rectangle Dim posBouton As System.Drawing.Point UnBouton.Width 20 : UnBouton.Height 21 posBouton.X 0 : posBouton.Y 0 '2 = 0 inactif, 1 mouveenter, 2 mouseclick '1 = 0 minimiz, 1 close For i = 0 To 2 dstRect(i, 0) = New System.Drawing.Rectangle(posBouton.X, posBouton.Y, UnBouton.Width, UnBouton.Height) dstRect(i, 1) = New System.Drawing.Rectangle(posBouton.X + UnBouton.Width, posBouton.Y, UnBouton.Width, UnBouton.Height) posBouton.Y = posBouton.Y + UnBouton.Height Next For i = 0 To 5 Step 2 myBitmap(i) = New System.Drawing.Bitmap(myImage, UnBouton.Width, UnBouton.Height) myGraphic = System.Drawing.Graphics.FromImage(myBitmap(i)) For j = 0 To 2 myGraphic.DrawImage(myBitmap(i), dstRect(j, 0), srcRect, Drawing.GraphicsUnit.Pixel) myGraphic.DrawImage(myBitmap(i), dstRect(j, 1), srcRect, Drawing.GraphicsUnit.Pixel) Next Next End Sub
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 System.Drawing.Image = System.Drawing.Image.FromFile(sI) Dim srcRect As New System.Drawing.Rectangle(0, 0, 44, 69) Dim i, j As Integer Dim dstRect(2, 1) As System.Drawing.Rectangle Dim myBitmap(5) As System.Drawing.Bitmap Dim myGraphic As System.Drawing.Graphics Dim UnBouton As System.Drawing.Rectangle Dim posBouton As System.Drawing.Point UnBouton.Width 20 : UnBouton.Height 21 posBouton.X 0 : posBouton.Y 0 '2 = 0 inactif, 1 mouveenter, 2 mouseclick '1 = 0 minimiz, 1 close For i = 0 To 2 dstRect(i, 0) = New System.Drawing.Rectangle(posBouton.X, posBouton.Y, UnBouton.Width, UnBouton.Height) dstRect(i, 1) = New System.Drawing.Rectangle(posBouton.X + UnBouton.Width, posBouton.Y, UnBouton.Width, UnBouton.Height) posBouton.Y = posBouton.Y + UnBouton.Height Next For i = 0 To 5 Step 2 myBitmap(i) = New System.Drawing.Bitmap(myImage) myBitmap(i + 1) = New System.Drawing.Bitmap(myImage) myGraphic = System.Drawing.Graphics.FromImage(myBitmap(i)) For j = 0 To 2 myGraphic.DrawImage(myBitmap(i), dstRect(j, 0), srcRect, Drawing.GraphicsUnit.Pixel) myGraphic.DrawImage(myBitmap(i + 1), dstRect(j, 1), srcRect, Drawing.GraphicsUnit.Pixel) Next Next PictureBox2.Image = myBitmap(4) End Sub
Structure MonImage Friend ImageWidth As Long Friend ImageHeight As Long Private nbBlocsLargeur As Long Private nbBlocsHauteur As Long Property NombreBlocsLargeur() Get Return nbBlocsLargeur End Get Set(ByVal value) nbBlocsLargeur = value End Set End Property Property NombreBlocsHauteur() Get Return nbBlocsHauteur End Get Set(ByVal value) nbBlocsHauteur = value End Set End Property Friend BlocWidth As Long Friend BlocHeight As Long End Structure
Structure MonImage Public myImage As System.Drawing.Image 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 ImageSource(ByVal CheminFichierImage As String) myImage = System.Drawing.Image.FromFile(CheminFichierImage) ImageWidth = myImage.Width ImageHeight = myImage.Height 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 .ImageSource(sI) .DefinirUnBloc(44, 69, 2, 3) End With
Imports System.Drawing Imports System.Drawing.Graphics Imports System.Drawing.Rectangle Imports System.Drawing.Drawing2D Imports System.Drawing.Color Imports System.Windows.Forms.Form
Structure MonImage Public myImage As Image 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) myImage = Image.FromFile(CheminFichierImage) ImageWidth = myImage.Width ImageHeight = myImage.Height End Sub Sub CloseImage() myImage = Nothing End Sub Function AfficherBloc(ByVal idbLargeur As Integer, ByVal idbHauteur As Integer) As System.Drawing.Bitmap Dim myBitmap As Bitmap Dim myGraphic As Graphics Dim myRegion As New Region Dim myRect As RectangleF myBitmap = New Bitmap(myImage) myGraphic = System.Drawing.Graphics.FromImage(myBitmap) myRect = myRegion.GetBounds(myGraphic) myRect.X = BlocWidth * idbLargeur myRect.Y = BlocHeight * idbHauteur myGraphic.DrawImage(myBitmap, myRect) AfficherBloc = myBitmap myGraphic = Nothing myBitmap = Nothing End Function 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) .DefinirUnBloc(44, 69, 2, 3) PictureBox2.Image = .AfficherBloc(1, 0) .CloseImage() End With End Sub
Structure MonImage Public myImage As Image 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) myImage = Image.FromFile(CheminFichierImage) ImageWidth = myImage.Width ImageHeight = myImage.Height End Sub Sub CloseImage() myImage = Nothing End Sub Function AfficherBloc(ByVal idbLargeur As Integer, ByVal idbHauteur As Integer) As System.Drawing.Bitmap Dim myBitmap As Bitmap Dim myGraphic As Graphics Dim myRegion As New Region Dim myDstRect, mySrcRect As New RectangleF myBitmap = New Bitmap(myImage) myGraphic = System.Drawing.Graphics.FromImage(myBitmap) mySrcRect = myRegion.GetBounds(myGraphic) myDstRect.X = BlocWidth * idbLargeur myDstRect.Y = BlocHeight * (idbHauteur - 1) myDstRect.Width = BlocWidth myDstRect.Width = BlocHeight myGraphic.DrawImage(myBitmap, myDstRect, mySrcRect, GraphicsUnit.Pixel) AfficherBloc = myBitmap myGraphic = Nothing myBitmap = Nothing End Function 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) .DefinirUnBloc(20, 21, 1, 3) PictureBox2.Image = .AfficherBloc(1, 3) .CloseImage() End With End Sub
Sub AfficherBloc(ByVal idbLargeur As Integer, ByVal idbHauteur As Integer) Dim myBitmap As Bitmap Dim myGraphic As Graphics Dim myPoint As New PointF Dim mydRect, mysRect As RectangleF myBitmap = New Bitmap(myImage) myGraphic = System.Drawing.Graphics.FromImage(myBitmap) myPoint.X = BlocWidth * (idbLargeur - 1) myPoint.Y = BlocHeight * (idbHauteur - 1) mysRect.X = myPoint.X mysRect.Y = myPoint.Y mysRect.Width = ImageWidth mysRect.Height = ImageHeight mydRect.X = 0 mydRect.Y = 0 mydRect.Width = BlocWidth mydRect.Height = BlocHeight myGraphic.DrawImage(myBitmap, mydRect, mysRect, GraphicsUnit.Pixel) myGraphic.Dispose() myPicture.Image = myBitmap 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
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 myBitmap As Bitmap Dim myGraphic As Graphics Dim myPoint As New PointF Dim mydRect, mysRect As RectangleF myBitmap = New Bitmap(myImage) myGraphic = System.Drawing.Graphics.FromImage(myBitmap) myPoint.X = BlocWidth * (idbLargeur - 1) myPoint.Y = BlocHeight * (idbHauteur - 1) mysRect.X = myPoint.X mysRect.Y = myPoint.Y mysRect.Width = ImageWidth mysRect.Height = ImageHeight mydRect.X = 0 mydRect.Y = 0 mydRect.Width = BlocWidth mydRect.Height = BlocHeight myGraphic.DrawImage(myBitmap, mydRect, mysRect, GraphicsUnit.Pixel) myGraphic.Dispose() myPicture.Image = myBitmap 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
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 nbBlocs As Integer = (nbBlocsLargeur * nbBlocsHauteur) Dim myBitmap(nbBlocsLargeur, nbBlocsHauteur) As Bitmap Dim myGraphic As Graphics Dim myPoint As New PointF Dim mydRect, mysRect As RectangleF Dim i, j As Integer For i = 1 To idbLargeur For j = 1 To idbHauteur myBitmap(i) = New Bitmap(myImage) myGraphic = System.Drawing.Graphics.FromImage(myBitmap(i)) myPoint.X = BlocWidth * (idbLargeur - 1) myPoint.Y = BlocHeight * (idbHauteur - 1) myGraphic.DrawImage(myBitmap(i), 0, 0, New RectangleF(0, 0, 15, 15), GraphicsUnit.Pixel) Next Next 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
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, nbBlocsHauteur) 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() 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