IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Lire une image le plus vite possible


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Informatique, programmation
    Inscrit en
    Novembre 2010
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Informatique, programmation

    Informations forums :
    Inscription : Novembre 2010
    Messages : 33
    Par défaut Lire une image le plus vite possible
    Bonjour,

    Qu'elle est la méthode pour lire une image le plus rapidement possible ?

    But: Lire une image Pixel par Pixel et stoker les couleurs dans un tableau (pour l’exemple)

    J'ai lue sur le net qu'il est déconseillé d'utiliser les méthode SetPixel et GetPixel car elle sont horriblement longue !

    Mais alors, comment faire autrement sans ces méthode-ci ?!

  2. #2
    Modérateur
    Avatar de DotNetMatt
    Homme Profil pro
    CTO
    Inscrit en
    Février 2010
    Messages
    3 611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : CTO
    Secteur : Finance

    Informations forums :
    Inscription : Février 2010
    Messages : 3 611
    Billets dans le blog
    3
    Par défaut
    As-tu essayé avec Bitmap.LockBits et Bitmap.UnlockBits ?

    [EDIT] : Un exemple est fourni ici
    Less Is More
    Pensez à utiliser les boutons , et les balises code
    Desole pour l'absence d'accents, clavier US oblige
    Celui qui pense qu'un professionnel coute cher n'a aucune idee de ce que peut lui couter un incompetent.

  3. #3
    Membre actif
    Homme Profil pro
    Informatique, programmation
    Inscrit en
    Novembre 2010
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Informatique, programmation

    Informations forums :
    Inscription : Novembre 2010
    Messages : 33
    Par défaut
    Je te remercie

    j'avoue que c'est un peu compliquer pour moi
    N'y à t-il vraiment aucun exemple en VB.Net sur ceci ?

  4. #4
    Modérateur
    Avatar de DotNetMatt
    Homme Profil pro
    CTO
    Inscrit en
    Février 2010
    Messages
    3 611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : CTO
    Secteur : Finance

    Informations forums :
    Inscription : Février 2010
    Messages : 3 611
    Billets dans le blog
    3
    Par défaut
    Tu peux utiliser des outils de conversion C# -> VB.NET tels que celui-ci : http://www.developerfusion.com/tools.../csharp-to-vb/

    Ca fonctionne dans la plupart des cas, cependant c'est un peu comme un traducteur de langues, ils n'arrivent pas à tout traduire à coup sûr. Mais bon ça va te dégrossir le travail
    Less Is More
    Pensez à utiliser les boutons , et les balises code
    Desole pour l'absence d'accents, clavier US oblige
    Celui qui pense qu'un professionnel coute cher n'a aucune idee de ce que peut lui couter un incompetent.

  5. #5
    Membre actif
    Homme Profil pro
    Informatique, programmation
    Inscrit en
    Novembre 2010
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Informatique, programmation

    Informations forums :
    Inscription : Novembre 2010
    Messages : 33
    Par défaut
    Oui, c'est vraie
    Mais vue que je débute, je suis même pas capable de "Réparer" un code traduit

    Donc comme dabe quoi, je vais devoir attendre en pleurnichant que une personne de bonne âme veuille bien m'aider

    En tout cas merci encore

    Bon déjà ya se code que je sais même pas comment on fais pour le faire marcher:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    Private Sub LockUnlockBitsExample(ByVal e As PaintEventArgs)
     
            ' Create a new bitmap. 
            Dim bmp As New Bitmap("c:\fakePhoto.jpg")
     
            ' Lock the bitmap's bits.   
            Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
            Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect, _
                Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat)
     
            ' Get the address of the first line. 
            Dim ptr As IntPtr = bmpData.Scan0
     
            ' Declare an array to hold the bytes of the bitmap. 
            ' This code is specific to a bitmap with 24 bits per pixels. 
            Dim bytes As Integer = Math.Abs(bmpData.Stride) * bmp.Height
            Dim rgbValues(bytes - 1) As Byte
     
            ' Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)
     
            ' Set every third value to 255. A 24bpp image will look red. 
            For counter As Integer = 2 To rgbValues.Length - 1 Step 3
                rgbValues(counter) = 255
            Next
     
            ' Copy the RGB values back to the bitmap
            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes)
     
            ' Unlock the bits.
            bmp.UnlockBits(bmpData)
     
            ' Draw the modified image.
            e.Graphics.DrawImage(bmp, 0, 150)
     
        End Sub
    Ensuite ce code traduis avec le programme qui tu m'as donner ou je comprends rien et qui fonctionne même pas en plus !
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    Public Class LockBitmap
    	Private source As Bitmap = Nothing
    	Private Iptr As IntPtr = IntPtr.Zero
    	Private bitmapData As BitmapData = Nothing
     
    	Public Property Pixels() As Byte()
    		Get
    			Return m_Pixels
    		End Get
    		Set
    			m_Pixels = Value
    		End Set
    	End Property
    	Private m_Pixels As Byte()
    	Public Property Depth() As Integer
    		Get
    			Return m_Depth
    		End Get
    		Private Set
    			m_Depth = Value
    		End Set
    	End Property
    	Private m_Depth As Integer
    	Public Property Width() As Integer
    		Get
    			Return m_Width
    		End Get
    		Private Set
    			m_Width = Value
    		End Set
    	End Property
    	Private m_Width As Integer
    	Public Property Height() As Integer
    		Get
    			Return m_Height
    		End Get
    		Private Set
    			m_Height = Value
    		End Set
    	End Property
    	Private m_Height As Integer
     
    	Public Sub New(source As Bitmap)
    		Me.source = source
    	End Sub
     
    	''' <summary>
    	''' Lock bitmap data
    	''' </summary>
    	Public Sub LockBits()
    		Try
    			' Get width and height of bitmap
    			Width = source.Width
    			Height = source.Height
     
    			' get total locked pixels count
    			Dim PixelCount As Integer = Width * Height
     
    			' Create rectangle to lock
    			Dim rect As New Rectangle(0, 0, Width, Height)
     
    			' get source bitmap pixel format size
    			Depth = System.Drawing.Bitmap.GetPixelFormatSize(source.PixelFormat)
     
    			' Check if bpp (Bits Per Pixel) is 8, 24, or 32
    			If Depth <> 8 AndAlso Depth <> 24 AndAlso Depth <> 32 Then
    				Throw New ArgumentException("Only 8, 24 and 32 bpp images are supported.")
    			End If
     
    			' Lock bitmap and return bitmap data
    			bitmapData = source.LockBits(rect, ImageLockMode.ReadWrite, source.PixelFormat)
     
    			' create byte array to copy pixel values
    			Dim [step] As Integer = Depth \ 8
    			Pixels = New Byte(PixelCount * [step] - 1) {}
    			Iptr = bitmapData.Scan0
     
    			' Copy data from pointer to array
    			Marshal.Copy(Iptr, Pixels, 0, Pixels.Length)
    		Catch ex As Exception
    			Throw ex
    		End Try
    	End Sub
     
    	''' <summary>
    	''' Unlock bitmap data
    	''' </summary>
    	Public Sub UnlockBits()
    		Try
    			' Copy data from byte array to pointer
    			Marshal.Copy(Pixels, 0, Iptr, Pixels.Length)
     
    			' Unlock bitmap data
    			source.UnlockBits(bitmapData)
    		Catch ex As Exception
    			Throw ex
    		End Try
    	End Sub
     
    	''' <summary>
    	''' Get the color of the specified pixel
    	''' </summary>
    	''' <param name="x"></param>
    	''' <param name="y"></param>
    	''' <returns></returns>
    	Public Function GetPixel(x As Integer, y As Integer) As Color
    		Dim clr As Color = Color.Empty
     
    		' Get color components count
    		Dim cCount As Integer = Depth \ 8
     
    		' Get start index of the specified pixel
    		Dim i As Integer = ((y * Width) + x) * cCount
     
    		If i > Pixels.Length - cCount Then
    			Throw New IndexOutOfRangeException()
    		End If
     
    		If Depth = 32 Then
    			' For 32 bpp get Red, Green, Blue and Alpha
    			Dim b As Byte = Pixels(i)
    			Dim g As Byte = Pixels(i + 1)
    			Dim r As Byte = Pixels(i + 2)
    			Dim a As Byte = Pixels(i + 3)
    			' a
    			clr = Color.FromArgb(a, r, g, b)
    		End If
    		If Depth = 24 Then
    			' For 24 bpp get Red, Green and Blue
    			Dim b As Byte = Pixels(i)
    			Dim g As Byte = Pixels(i + 1)
    			Dim r As Byte = Pixels(i + 2)
    			clr = Color.FromArgb(r, g, b)
    		End If
    		If Depth = 8 Then
    			' For 8 bpp get color value (Red, Green and Blue values are the same)
    			Dim c As Byte = Pixels(i)
    			clr = Color.FromArgb(c, c, c)
    		End If
    		Return clr
    	End Function
     
    	''' <summary>
    	''' Set the color of the specified pixel
    	''' </summary>
    	''' <param name="x"></param>
    	''' <param name="y"></param>
    	''' <param name="color"></param>
    	Public Sub SetPixel(x As Integer, y As Integer, color As Color)
    		' Get color components count
    		Dim cCount As Integer = Depth \ 8
     
    		' Get start index of the specified pixel
    		Dim i As Integer = ((y * Width) + x) * cCount
     
    		If Depth = 32 Then
    			' For 32 bpp set Red, Green, Blue and Alpha
    			Pixels(i) = color.B
    			Pixels(i + 1) = color.G
    			Pixels(i + 2) = color.R
    			Pixels(i + 3) = color.A
    		End If
    		If Depth = 24 Then
    			' For 24 bpp set Red, Green and Blue
    			Pixels(i) = color.B
    			Pixels(i + 1) = color.G
    			Pixels(i + 2) = color.R
    		End If
    		If Depth = 8 Then
    			' For 8 bpp set color value (Red, Green and Blue values are the same)
    			Pixels(i) = color.B
    		End If
    	End Sub
    End Class
    Voilà, c'est tous... pour le moment !

  6. #6
    Membre actif
    Homme Profil pro
    Aucune
    Inscrit en
    Mars 2014
    Messages
    34
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Aucune

    Informations forums :
    Inscription : Mars 2014
    Messages : 34
    Par défaut
    Ah mince, moi qui cherchais justement la solution à se même problème suis déçus qu'il n'y est pas eu une réponse plus précise pour un débutant
    J'ai essayer de lire une image, et de la reproduire pour un test, c'est hyper long comme traitement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Dim ImageLecture As New Bitmap("Mon Image")
            Dim ImageReproduction As New Bitmap(ImageLecture.Width, ImageLecture.Height)
            Dim Couleur As System.Drawing.Color
     
            ' Lecture et reproduction de l'image
            For Y = 0 To ImageLecture.Height - 1 Step 1
                For X = 0 To ImageLecture.Width - 1 Step 1
                    Couleur = ImageLecture.GetPixel(X, Y)
                    ImageReproduction.SetPixel(X, Y, Couleur)
                Next
            Next
    Avec une image de 4096 par 4096, ça met 25 secondes avec mon ordi, c'est très long
    En faite je cherche le moyen de pouvoir manipuler les informations des pixels de l'image.

    En plus s'il faut faire un traitement sur chaque pixel de l'image, ça va prendre une éternité
    Possibilité d'avoir une aide svp

Discussions similaires

  1. Agrandir une image le plus possible
    Par Array dans le forum OpenCV
    Réponses: 1
    Dernier message: 20/04/2009, 22h19
  2. Réponses: 3
    Dernier message: 27/04/2006, 13h33
  3. Lire une image Tiff en C/cpp avec Lib tiff
    Par syn_42 dans le forum MFC
    Réponses: 4
    Dernier message: 04/01/2006, 21h28
  4. lire une image et tracer une fonction
    Par Battosaiii dans le forum C
    Réponses: 4
    Dernier message: 23/11/2005, 15h21
  5. lire une image au format RAW
    Par Anonymous dans le forum OpenGL
    Réponses: 5
    Dernier message: 20/05/2002, 00h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo