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

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 à 12:04
Il me coupe pas mon image mais me le redimensionne !!!

PLEASE HELP !!!!




    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
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 à 12:09
J'fait un break, ras l' bole !

Si vous voulez m'aider un peu le code est juste au dessus et j'ai
upload l'image test ici:

http://img4.hostingpics.net/pics/480399button.gif
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 à 13:22
Super Henry !!!

Sa fonctionne bien ^^ j'ai plus qu'a ajuster le rectangle avec un
paramètre de marge qui entoure chaque bloc.
Je colle le code dès que ca fonctionne.

ENCORE MERCI !
0
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 à 18:19
De rien :)

Parfois, on cherche trop compliqué :)

0

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

Posez votre question
Utilisateur anonyme
5 nov. 2010 à 19:56
Salut,
Pense aussi à la gestion des erreurs (fichier image corrompu par exemple).
Cette ligne est hasardeuse :
myBitmap = New Bitmap(CheminFichierImage)

a+
0
Rejoignez-nous