Actuellement je charge une image dans un PictureBox ou je crée un graphique
utilisant une image
Je sais sauvegarder l'image entiere
Mais je n'arrive pas à sauvegarder une partie de l'image.
Les fonctions de System.Drawing.Graphics suffisent-elles ou faut-il ajouter
une référence au projet ?
Nota: en VB6 j'utilisais un Olympus PicBuf qui avait beaucoup de propriétés
et méthodes mais VB.net l'a encapsulé et il se retrouve avec les mêmes
propriétés et méthodes que PictureBox.image
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Millox Frédéric
Salut Euclide,
Private Function ExtractAndCreateImg(ByVal PathImgToCreate As String, ByVal FormatToCreate As System.Drawing.Imaging.ImageFormat, _ ByVal PathImgToExtract As String, ByVal Units As GraphicsUnit, ByVal ImgX As Int32, ByVal ImgY As Int32, _ ByVal ImgWidth As Int32, ByVal ImgHeight As Int32) As Boolean Dim imgTemp As System.Drawing.Image Dim gTemp As System.Drawing.Graphics Dim bTemp As System.Drawing.Bitmap Dim rectTemp As System.Drawing.Rectangle Dim result As Boolean
result = True Try imgTemp = System.Drawing.Image.FromFile(PathImgToExtract) rectTemp = New System.Drawing.Rectangle(ImgX, ImgY, ImgWidth, ImgHeight) bTemp = New System.Drawing.Bitmap(ImgWidth, ImgHeight, Imaging.PixelFormat.Format32bppRgb) gTemp = System.Drawing.Graphics.FromImage(bTemp) gTemp.DrawImage(imgTemp, 0, 0, rectTemp, Units) bTemp.Save(PathImgToCreate, FormatToCreate)
Catch ex As Exception result = False Finally If Not imgTemp Is Nothing Then imgTemp.Dispose() If Not gTemp Is Nothing Then gTemp.Dispose() If Not bTemp Is Nothing Then bTemp.Dispose() imgTemp = Nothing gTemp = Nothing bTemp = Nothing rectTemp = Nothing End Try
Return result End Function
Sachant le couple (ImgX, ImgY) représente la coordonnées du point en haut à gauche du rectangle que tu veux extraire ( une partie de l'image ? ) et ImgWidth, ImgHeight sont la largeur et la hauteur de ce même rectangle.
A+
-- fmillox
"Euclide" a écrit :
Actuellement je charge une image dans un PictureBox ou je crée un graphique utilisant une image Je sais sauvegarder l'image entiere Mais je n'arrive pas à sauvegarder une partie de l'image.
Les fonctions de System.Drawing.Graphics suffisent-elles ou faut-il ajouter une référence au projet ?
Nota: en VB6 j'utilisais un Olympus PicBuf qui avait beaucoup de propriétés et méthodes mais VB.net l'a encapsulé et il se retrouve avec les mêmes propriétés et méthodes que PictureBox.image
Comment faire ?
Salut Euclide,
Private Function ExtractAndCreateImg(ByVal PathImgToCreate As String, ByVal
FormatToCreate As System.Drawing.Imaging.ImageFormat, _
ByVal PathImgToExtract As String,
ByVal Units As GraphicsUnit, ByVal ImgX As Int32, ByVal ImgY As Int32, _
ByVal ImgWidth As Int32, ByVal
ImgHeight As Int32) As Boolean
Dim imgTemp As System.Drawing.Image
Dim gTemp As System.Drawing.Graphics
Dim bTemp As System.Drawing.Bitmap
Dim rectTemp As System.Drawing.Rectangle
Dim result As Boolean
result = True
Try
imgTemp = System.Drawing.Image.FromFile(PathImgToExtract)
rectTemp = New System.Drawing.Rectangle(ImgX, ImgY, ImgWidth,
ImgHeight)
bTemp = New System.Drawing.Bitmap(ImgWidth, ImgHeight,
Imaging.PixelFormat.Format32bppRgb)
gTemp = System.Drawing.Graphics.FromImage(bTemp)
gTemp.DrawImage(imgTemp, 0, 0, rectTemp, Units)
bTemp.Save(PathImgToCreate, FormatToCreate)
Catch ex As Exception
result = False
Finally
If Not imgTemp Is Nothing Then imgTemp.Dispose()
If Not gTemp Is Nothing Then gTemp.Dispose()
If Not bTemp Is Nothing Then bTemp.Dispose()
imgTemp = Nothing
gTemp = Nothing
bTemp = Nothing
rectTemp = Nothing
End Try
Return result
End Function
Sachant le couple (ImgX, ImgY) représente la coordonnées du point en haut à
gauche du rectangle que tu veux extraire ( une partie de l'image ? ) et
ImgWidth, ImgHeight sont la largeur et la hauteur de ce même rectangle.
A+
--
fmillox
"Euclide" a écrit :
Actuellement je charge une image dans un PictureBox ou je crée un graphique
utilisant une image
Je sais sauvegarder l'image entiere
Mais je n'arrive pas à sauvegarder une partie de l'image.
Les fonctions de System.Drawing.Graphics suffisent-elles ou faut-il ajouter
une référence au projet ?
Nota: en VB6 j'utilisais un Olympus PicBuf qui avait beaucoup de propriétés
et méthodes mais VB.net l'a encapsulé et il se retrouve avec les mêmes
propriétés et méthodes que PictureBox.image
Private Function ExtractAndCreateImg(ByVal PathImgToCreate As String, ByVal FormatToCreate As System.Drawing.Imaging.ImageFormat, _ ByVal PathImgToExtract As String, ByVal Units As GraphicsUnit, ByVal ImgX As Int32, ByVal ImgY As Int32, _ ByVal ImgWidth As Int32, ByVal ImgHeight As Int32) As Boolean Dim imgTemp As System.Drawing.Image Dim gTemp As System.Drawing.Graphics Dim bTemp As System.Drawing.Bitmap Dim rectTemp As System.Drawing.Rectangle Dim result As Boolean
result = True Try imgTemp = System.Drawing.Image.FromFile(PathImgToExtract) rectTemp = New System.Drawing.Rectangle(ImgX, ImgY, ImgWidth, ImgHeight) bTemp = New System.Drawing.Bitmap(ImgWidth, ImgHeight, Imaging.PixelFormat.Format32bppRgb) gTemp = System.Drawing.Graphics.FromImage(bTemp) gTemp.DrawImage(imgTemp, 0, 0, rectTemp, Units) bTemp.Save(PathImgToCreate, FormatToCreate)
Catch ex As Exception result = False Finally If Not imgTemp Is Nothing Then imgTemp.Dispose() If Not gTemp Is Nothing Then gTemp.Dispose() If Not bTemp Is Nothing Then bTemp.Dispose() imgTemp = Nothing gTemp = Nothing bTemp = Nothing rectTemp = Nothing End Try
Return result End Function
Sachant le couple (ImgX, ImgY) représente la coordonnées du point en haut à gauche du rectangle que tu veux extraire ( une partie de l'image ? ) et ImgWidth, ImgHeight sont la largeur et la hauteur de ce même rectangle.
A+
-- fmillox
"Euclide" a écrit :
Actuellement je charge une image dans un PictureBox ou je crée un graphique utilisant une image Je sais sauvegarder l'image entiere Mais je n'arrive pas à sauvegarder une partie de l'image.
Les fonctions de System.Drawing.Graphics suffisent-elles ou faut-il ajouter une référence au projet ?
Nota: en VB6 j'utilisais un Olympus PicBuf qui avait beaucoup de propriétés et méthodes mais VB.net l'a encapsulé et il se retrouve avec les mêmes propriétés et méthodes que PictureBox.image