Accueil > > > GETPIXEL TRÈS RAPIDE
GETPIXEL TRÈS RAPIDE
Information sur la source
Description
cette classe vous permet de prendre/écrire un pîxel sur une image beaucoup plus rapidement que la classe Bitmap du framework
Source
- Imports System.Drawing
- Imports System.Drawing.Imaging
- Public Class BitmapFast
-
- #Region "private"
- Private b() As Byte
- Private i_Width As Integer
- Private i_Height As Integer
- Private i_Stride As Integer
- Private i_ColorSize As Integer
- #End Region
-
- #Region "public"
- Public Disposed As Boolean
- #End Region
-
- #Region "New"
- Public Sub New(ByVal filename As String)
- If (filename = "") Or (System.IO.File.Exists(filename) = False) Then
- MsgBox("file '" & filename & "' not found!")
- Exit Sub
- End If
-
- Dim pv_bitmap As Bitmap = Nothing
- pv_bitmap = New Bitmap(filename)
- i_Width = pv_bitmap.Width
- i_Height = pv_bitmap.Height
-
- Dim bounds As Rectangle = New Rectangle(0, 0, i_Width, i_Height)
- Dim bitmapData As BitmapData = pv_bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
- i_stride = bitmapData.Stride
- i_ColorSize = bitmapData.Stride / bitmapData.Width
- ReDim b(bitmapData.Height * i_stride)
- System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, b, 0, b.Length - 1)
- pv_bitmap.UnlockBits(bitmapData)
-
- pv_bitmap.Dispose()
- pv_bitmap = Nothing
- End Sub
- #End Region
-
- #Region "Function"
- Public Function Getpixel(ByVal x As Integer, ByVal y As Integer) As Color
-
- Dim red, green, blue As Byte
- red = b(x * i_ColorSize + y * i_Stride)
- green = b((x * i_ColorSize + 1) + y * i_Stride)
- blue = b((x * i_ColorSize + 2) + y * i_Stride)
-
- Return Color.FromArgb(255, red, green, blue)
- End Function
-
- Public Sub Setpixel(ByVal x As Integer, ByVal y As Integer, ByVal color As Color)
- b(x * i_ColorSize + y * i_Stride) = color.R
- b((x * i_ColorSize + 1) + y * i_Stride) = color.G
- b((x * i_ColorSize + 2) + y * i_Stride) = color.B
- End Sub
- #End Region
-
- #Region "Save"
- Public Sub Save(ByVal filename As String, ByVal myFormat As ImageFormat)
- Dim pv_bitmap As Bitmap = Nothing
- pv_bitmap = New Bitmap(i_Width, i_Height, PixelFormat.Format24bppRgb)
-
- Dim bounds As Rectangle = New Rectangle(0, 0, i_Width, i_Height)
- Dim bitmapData As Imaging.BitmapData = pv_bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
-
- System.Runtime.InteropServices.Marshal.Copy(b, 0, bitmapData.Scan0, b.Length - 1)
- pv_bitmap.Save(filename, myFormat)
- pv_bitmap.UnlockBits(bitmapData)
-
- pv_bitmap.Dispose()
- pv_bitmap = Nothing
-
- End Sub
-
- #End Region
-
- #Region "GetBitmap"
- Public Function Get_Bitmap() As Bitmap
-
- Get_Bitmap = New Bitmap(i_Width, i_Height, PixelFormat.Format24bppRgb)
-
- Dim bounds As Rectangle = New Rectangle(0, 0, i_Width, i_Height)
- Dim bitmapData As Imaging.BitmapData = Get_Bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
- bitmapData.Stride = CInt(bitmapData.Stride / i_Width) * i_Width
- System.Runtime.InteropServices.Marshal.Copy(b, 0, bitmapData.Scan0, b.Length - 1)
- Get_Bitmap.UnlockBits(bitmapData)
-
- End Function
- #End Region
-
- #Region "property"
- Public ReadOnly Property Width() As Integer
- Get
- Return i_Width
- End Get
- End Property
-
- Public ReadOnly Property Height() As Integer
- Get
- Return i_Height
- End Get
- End Property
- #End Region
-
- #Region "dispose"
- Public Sub Dispose()
- If Disposed = True Then Exit Sub
- Erase b
- Disposed = True
- End Sub
-
- Protected Overrides Sub Finalize()
- MyBase.Finalize()
- If Disposed = False Then Dispose()
- End Sub
- #End Region
-
- End Class
Imports System.Drawing
Imports System.Drawing.Imaging
Public Class BitmapFast
#Region "private"
Private b() As Byte
Private i_Width As Integer
Private i_Height As Integer
Private i_Stride As Integer
Private i_ColorSize As Integer
#End Region
#Region "public"
Public Disposed As Boolean
#End Region
#Region "New"
Public Sub New(ByVal filename As String)
If (filename = "") Or (System.IO.File.Exists(filename) = False) Then
MsgBox("file '" & filename & "' not found!")
Exit Sub
End If
Dim pv_bitmap As Bitmap = Nothing
pv_bitmap = New Bitmap(filename)
i_Width = pv_bitmap.Width
i_Height = pv_bitmap.Height
Dim bounds As Rectangle = New Rectangle(0, 0, i_Width, i_Height)
Dim bitmapData As BitmapData = pv_bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
i_stride = bitmapData.Stride
i_ColorSize = bitmapData.Stride / bitmapData.Width
ReDim b(bitmapData.Height * i_stride)
System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, b, 0, b.Length - 1)
pv_bitmap.UnlockBits(bitmapData)
pv_bitmap.Dispose()
pv_bitmap = Nothing
End Sub
#End Region
#Region "Function"
Public Function Getpixel(ByVal x As Integer, ByVal y As Integer) As Color
Dim red, green, blue As Byte
red = b(x * i_ColorSize + y * i_Stride)
green = b((x * i_ColorSize + 1) + y * i_Stride)
blue = b((x * i_ColorSize + 2) + y * i_Stride)
Return Color.FromArgb(255, red, green, blue)
End Function
Public Sub Setpixel(ByVal x As Integer, ByVal y As Integer, ByVal color As Color)
b(x * i_ColorSize + y * i_Stride) = color.R
b((x * i_ColorSize + 1) + y * i_Stride) = color.G
b((x * i_ColorSize + 2) + y * i_Stride) = color.B
End Sub
#End Region
#Region "Save"
Public Sub Save(ByVal filename As String, ByVal myFormat As ImageFormat)
Dim pv_bitmap As Bitmap = Nothing
pv_bitmap = New Bitmap(i_Width, i_Height, PixelFormat.Format24bppRgb)
Dim bounds As Rectangle = New Rectangle(0, 0, i_Width, i_Height)
Dim bitmapData As Imaging.BitmapData = pv_bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
System.Runtime.InteropServices.Marshal.Copy(b, 0, bitmapData.Scan0, b.Length - 1)
pv_bitmap.Save(filename, myFormat)
pv_bitmap.UnlockBits(bitmapData)
pv_bitmap.Dispose()
pv_bitmap = Nothing
End Sub
#End Region
#Region "GetBitmap"
Public Function Get_Bitmap() As Bitmap
Get_Bitmap = New Bitmap(i_Width, i_Height, PixelFormat.Format24bppRgb)
Dim bounds As Rectangle = New Rectangle(0, 0, i_Width, i_Height)
Dim bitmapData As Imaging.BitmapData = Get_Bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
bitmapData.Stride = CInt(bitmapData.Stride / i_Width) * i_Width
System.Runtime.InteropServices.Marshal.Copy(b, 0, bitmapData.Scan0, b.Length - 1)
Get_Bitmap.UnlockBits(bitmapData)
End Function
#End Region
#Region "property"
Public ReadOnly Property Width() As Integer
Get
Return i_Width
End Get
End Property
Public ReadOnly Property Height() As Integer
Get
Return i_Height
End Get
End Property
#End Region
#Region "dispose"
Public Sub Dispose()
If Disposed = True Then Exit Sub
Erase b
Disposed = True
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
If Disposed = False Then Dispose()
End Sub
#End Region
End Class
Historique
- 20 avril 2006 10:36:14 :
- correction de la fonction setpixel
- 20 avril 2006 16:52:44 :
- Ajout de la fonction Get_Bitmap
- 24 avril 2007 21:01:58 :
- correction d'un petit bug.
- 03 janvier 2008 14:55:15 :
- Correction du décalage des pixels.
- 03 janvier 2008 20:47:14 :
- Correction de l'inversion du rouge et bleu.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Couleur SetPixel différente de couleure GetPixel sous Windows 2000 [ par cushy007 ]
Couleur SetPixel différente de couleure GetPixel sous Windows 2000 [ par cushy007 ]
Salut, J'ai un problème sous Windows 2000 avec les couleurs des API SetPixel et GetPixel. La couleur que me renvoie GetPixel est différente
SetPixel place mal le pixel [ par baouc ]
Bonjour à tous,voilà, je développe une appli sous vba depuis excel.Mon problème se situe au niveau d'une Userform (équivalent de la form), sur laquell
reduire backdrop d'un mschart URGENT [ par monsieurlemouche ]
bonjour,je cherche à donner des infos statistiques dans un flexgrid sous forme de courbe de gauss. Ne connaissant pas grand chose en programmation vb,
Modif de la taille d'une Bitmap apres sa definition [ par doxt ]
Peut ton redifinir la taille d'une bitmap apres sa definition Public Class Tutu Private BM as New bitmap (10,10) sub new BM.height =
Format8bppIndexed [ par loozer130467 ]
bonjour,Une charmante personne pourait-elle m expliquer comment changer les pixelformat d un bmp ,svp ?sa fait maintenant 3 jour que je suis coincer s
setpixel [ par jak12345 ]
comment utiliser la methode setpixel?
image en degrade de gris [ par jak12345 ]
Bonjour,Je veux declarer une image en degradé de gris puis affecter une teinte de gris à chacun de ses pixel. Mon code actuel est : Dim Bitmap
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
LISTER KEYS.KEYLISTER KEYS.KEY par Onin42
Cliquez pour lire la suite par Onin42
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|