Decouper une image en 6 bloc ?

Résolu
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 - 5 nov. 2010 à 07:45
 Utilisateur anonyme - 5 nov. 2010 à 19:56
Bonjour all,

objectif du jour, découper 6 blocs d'une image en mémoire et afficher
un bloc dans un picturebox.

Mon image fait 44x69
Voici le tableau:
_ _
|O|O|
- -
- -
|O|O|
- -
- -
|O|O|
- -

chaque trait représente une marge d'un pixel.
chaque rond représente un bloc a découper.

Premier soucis, y a plus le control IMAGE du vb6 :(
Je galère avec les namespaces, un vrai tas de nouilles !
Je retrouve bitmap et image dans la lib mais j'ai qu'un controle picturebox?

J'en suis là:
    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 myPicture As System.Drawing.Bitmap = PictureBox1.Image
        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 a As New System.Drawing.Graphics

        a.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel)


    End Sub


Le problème: a n'a aucun constructeur ???

25 réponses

NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
5 nov. 2010 à 12:39
Bonjour,

Je vais peut être poser une question bête, mais avec tout tes tests, je ne l'ai pas vu.

J'ai regardé la doc de l'objet Bitmap, et j'ai vu la fonction Clone :
http://msdn.microsoft.com/en-us/library/ms141944.aspx

Elle prend en paramètre une structure Rectangle, ne serait-ce pas la réponse à ta question ?

3
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 13:26
Même pas besoin de marge, sa dépend de l'image ^^
Code fonctionnel !

MERCIiiiiiiiiiiiiiiiiiiiiiiiiiiiii HENRY !


    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
3
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 08:02
Erreur 4 Type 'myDraw.DrawImage' non défini.

Dim myDraw As System.Drawing.Graphics

        PictureBox1.InitialImage = New myDraw.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel)
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 08:05
Erreur 4 Une valeur de type 'System.Drawing.Image' ne peut pas être convertie en 'System.Drawing.Graphics'

      Dim myDraw As System.Drawing.Graphics
        myDraw = PictureBox1.Image
        myDraw.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 08:23
Erreur 4 'DrawImage' n'est pas un membre de 'System.Windows.Forms.PaintEventArgs'.

Ouai c'est logique j'suis pas dans un _paintevent et alors j'peux pas le
faire depuis un bouton ???

        Dim a As System.Windows.Forms.PaintEventArgs
        a.DrawImage(myImage, dstRect(2, 1), srcRect, Drawing.GraphicsUnit.Pixel)
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 08:40
RIEN NE S'PASSE ???

    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 08:56
HUmm... j'ai pas fini encore !

    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 09:26
J'ai un début de ked choz ^^

EFFET ZOOM INCRUTAGE

    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 09:44
Je reprend tout...

    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 09:55
    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 10:12
FINI LES NAMESPACES A LA *** !!!
Comment c'est plus pratique ^^ WAH !

Imports System.Drawing
Imports System.Drawing.Graphics
Imports System.Drawing.Rectangle
Imports System.Drawing.Drawing2D
Imports System.Drawing.Color
Imports System.Windows.Forms.Form
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 10:20
Bon sa affiche l'image entière, c'est un bon début !
La structure semble assez good !

    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 10:22
Une question au passage si un amateur ou expert VB.NET passe par là...

VB.NET me détruit automatiquement le " Dim myImage As New MonImage " une fois sortie du sub ?
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 10:36
Sa m'affiche toujours l'image entière, j'arrive pas a faire une découpe :(
Je sais pas me servir de REGION ni du RECTANGLE !
Je pensais que la fusion de deux rectangles et imgsource avec drawimage fonctionnerait:(

   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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 10:38
J'vin de corriger une petite erreur...
DefinirUnBloc(20, 21, 2, 3)
Ce qui fait 2x3 = 6 blocs de 20 x 21



Objectif afficher le dernier bloc càd:
.AfficherBloc(2, 3)
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 10:59
Si quelqu'un veut m'aider ce serait maintenant !
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 11:23
J'galère dur depuis 6h00 du mat !
Quelqu'un pourrait m'aider si vous plé :(

        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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 11:24
    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 11:39
PENSE, PENSE, PENSE comme dirait Winnie l'ourson ^^
j'ai pas encore fini !

    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
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
5 nov. 2010 à 11:59
Sa avance lentement...

    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
0
Rejoignez-nous