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
GetPixel et SetPixel [ par MoiDebutantVB ]
Je me rapelle avoir vu une source .Net qui utilisait GetPixel et Set Pixel ainsi qu'une Api et une autre méthode pour remplacer une couleur d'une bitm
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?
Sauvegarder un objet graphics... [ par MoiDebutantVB ]
Bonjour !Comment faire pour charger un objet graphics dans un objet bitmap, pour ensuite sauvegader le bitmap ??? Merci Beaucoup en tout cas,CFP.
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
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|