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

C# Discussion :

Modifier couleur pixel - PictureBox


Sujet :

C#

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 71
    Points : 48
    Points
    48
    Par défaut Modifier couleur pixel - PictureBox
    Bonjour,

    J'ai une image affichée dans une Form à l'aide d'un PictureBox.

    Y a-t-il moyen de remplacer une couleur par une autre en donnant le code RVB par exemple?

    Merci

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 71
    Points : 48
    Points
    48
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    for(int i=0;i<640;i++)
                {
                    for(int j=0;j<383;j++)
                    {
                        if (!myBitmap.GetPixel(i, j).ToString().Equals("Color [A=0, R=206, G=237, B=220]"))
                            myBitmap.SetPixel(i,j, Color.Azure);
                    }
                }
     
                pictureBox21.Image = myBitmap;

  3. #3
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Pour de meiilleures que GetPixel() qui est lent :
    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
    using System.Drawing;
    using System.Drawing.Imaging;
    public class BitmapFast
    {
    #region private
    private byte[] b;
    private int i_Width;
    private int i_Height;
    private int i_Stride;
    private int i_ColorSize;
    #endregion
    #region public
    public bool Disposed;
    #endregion
    #region New
    public BitmapFast(string filename)
    {
    if ((filename == "") | (System.IO.File.Exists(filename) == false)) {
    MsgBox("file '" + filename + "' not found!");
    return;
    }
    Bitmap pv_bitmap = null;
    pv_bitmap = new Bitmap(filename);
    i_Width = pv_bitmap.Width;
    i_Height = pv_bitmap.Height;
    Rectangle bounds = new Rectangle(0, 0, i_Width, i_Height);
    BitmapData bitmapData = pv_bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    i_stride = bitmapData.Stride;
    i_ColorSize = bitmapData.Stride / bitmapData.Width;
    // ERROR: Not supported in C#: ReDimStatement
    System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, b, 0, b.Length - 1);
    pv_bitmap.UnlockBits(bitmapData);
    pv_bitmap.Dispose();
    pv_bitmap = null;
    }
    #endregion
    #region Function
    public Color Getpixel(int x, int y)
    {
    byte red;
    byte green;
    byte blue;
    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);
    }
    public void Setpixel(int x, int y, Color 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;
    }
    #endregion
    #region Save
    public void Save(string filename, ImageFormat myFormat)
    {
    Bitmap pv_bitmap = null;
    pv_bitmap = new Bitmap(i_Width, i_Height, PixelFormat.Format24bppRgb);
    Rectangle bounds = new Rectangle(0, 0, i_Width, i_Height);
    Imaging.BitmapData 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 = null;
    }
    #endregion
    #region GetBitmap
    public Bitmap Get_Bitmap()
    {
    Get_Bitmap = new Bitmap(i_Width, i_Height, PixelFormat.Format24bppRgb);
    Rectangle bounds = new Rectangle(0, 0, i_Width, i_Height);
    Imaging.BitmapData bitmapData = Get_Bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    bitmapData.Stride = (int)bitmapData.Stride / i_Width * i_Width;
    System.Runtime.InteropServices.Marshal.Copy(b, 0, bitmapData.Scan0, b.Length - 1);
    Get_Bitmap.UnlockBits(bitmapData);
    }
    #endregion
    #region property
    public int Width {
    get { return i_Width; }
    }
    public int Height {
    get { return i_Height; }
    }
    #endregion
    #region dispose
    public void Dispose()
    {
    if (Disposed == true) return;
    b = null;
    Disposed = true;
    }
    protected override void Finalize()
    {
    base.Finalize();
    if (Disposed == false) Dispose();
    }
    #endregion
    }

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 71
    Points : 48
    Points
    48
    Par défaut
    Bonjour,

    C'est bien plus rapide, merci!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. modifier couleur zone réactive
    Par totoranky dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 01/07/2010, 23h18
  2. CListCtrl: modifier couleur item
    Par luareon22 dans le forum MFC
    Réponses: 2
    Dernier message: 31/03/2006, 14h48
  3. modifier couleur lien
    Par linniesurf dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 30/12/2005, 11h55
  4. Modifier couleurs arrière-plan dossiers
    Par marcus333 dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 16/09/2005, 13h19
  5. [VB.NET] Comment envoyer un texte modifié(couleurs,style...)
    Par fdiedler dans le forum Windows Forms
    Réponses: 8
    Dernier message: 14/03/2005, 18h11

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