Results 1 to 4 of 4

Thread: Changing Color of Simple Bitmaps

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2011
    Location
    Melbourne
    Posts
    53

    Changing Color of Simple Bitmaps

    If I load a bitmap let's say it has only two colors, white pixels on black pixels.

    Code:
    Dim myBitmap As Bitmap
    myBitmap = Bitmap.FromFile("file.bmp")

    Name:  9CjAXuW.png
Views: 302
Size:  379 Bytes

    Could I change the foreground white pixels to another color at runtime?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Changing Color of Simple Bitmaps

    you can change a color in a bitmap with image attributes:

    Name:  17-04-2013 23.25.54.jpg
Views: 192
Size:  16.4 KB

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim img1 As New Bitmap(PictureBox2.Width, PictureBox2.Height)
            Dim att As System.Drawing.Imaging.ImageAttributes = New System.Drawing.Imaging.ImageAttributes
            Dim map(0) As System.Drawing.Imaging.ColorMap
            map(0) = New System.Drawing.Imaging.ColorMap
            map(0).OldColor = Color.White
            map(0).NewColor = Color.Red
            att.SetRemapTable(map)
    
            Dim gr As Graphics = Graphics.FromImage(img1)
            gr.DrawImage(PictureBox1.Image, New Point() {Point.Empty, New Point(img1.Width, 0), New Point(0, img1.Height)}, New Rectangle(Point.Empty, img1.Size), GraphicsUnit.Pixel, att)
            PictureBox2.Image = img1
        End Sub
    
    End Class

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2011
    Location
    Melbourne
    Posts
    53

    Re: Changing Color of Simple Bitmaps

    That looks perfect, thanks Paul

  4. #4
    New Member
    Join Date
    Apr 2013
    Posts
    6

    Re: Changing Color of Simple Bitmaps

    Thank you Paul, that code was precisely what I was looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width