+ Reply to Thread
Results 1 to 2 of 2

Thread: apply color value to BitmapImage

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    10

    apply color value to BitmapImage

    I have to create a bitmap image using a color value like "Black"
    Then i must create a black bitmap image and so on...
    I do not know how to create a bitmap image , so i was wondering if you guys could help me out with this?

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    36
    You can create ImageBrush from BitmapSource:
    Code:
        private BitmapSource CreateBitmapSource(System.Windows.Media.Color color)
        {
            int width = 128;
            int height = width;
            int stride = width / 8;
            byte[] pixels = new byte[height * stride];
    
            List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>();
            colors.Add(color);
            BitmapPalette myPalette = new BitmapPalette(colors);
    
            BitmapSource image = BitmapSource.Create(
                width,
                height,
                96,
                96,
                PixelFormats.Indexed1,
                myPalette,
                pixels,
                stride);
    
            return image;
        }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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