Public Group

# .NET/C# Bitmap using colour

This topic is 4074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay, I'm working on a quick program to plot a few graphs for interest's sake. I'm using a PictureBox with its Dock attribute set to Fill to display a Bitmap (generated at the appropriate size every time the Form is resized) which hopefully contains the graph. However, I'm having a really beginner-type problem that I just can't understand. The graphs are of functions of the form
f(x)  = g(f(x)   )
n         n-1

(i.e. I'm doing a number of iterations with a function where the output of one iteration is the input to the next) For various different different functions, g(). As a result, I need to produce a 2D image with different intensities of colour depending on the number of times any particular point in the 2D space is 'hit'. (Kind of like the colouring of fractals by the number of iterations required for that pixel to 'escape') Anyway, the actual graph-drawing bit boils down to essentially Bitmap someBitmap = new Bitmap(width, height); someBitmap.SetPixel(x, y, Color.fromArgb(alpha, r, g, b)); repeated several million times. But, bizarrely, I can't get the line to show up in colour -- just black or white even if I have something like alpha=0, r=255, g=0, b=0. I also tried Color.fromArgb using an int as a 32 bit encoded ARGB value but that only worked in black and white, too. I've done stuff using Bitmap, Image and PictureBox before so I don't know what I'm missing this time. Any ideas?

##### Share on other sites
I guess this isn't the problem, but the alpha should be 255 and not 0 if you want anything to show up. Also make sure the pixel format of the Bitmap is right (not 2 bit black/white) - for instance PixelFormat.Format32bppRgb.

##### Share on other sites
Quote:
 Original post by e-u-l-o-g-yI guess this isn't the problem, but the alpha should be 255 and not 0 if you want anything to show up.

Well, that's egg on my face, then! That was the problem; have a rate++.

[grin]

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 9
• 9
• 46
• 41
• ### Forum Statistics

• Total Topics
631750
• Total Posts
3002065
×