Sign in to follow this  
TheUnbeliever

.NET/C# Bitmap using colour

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by e-u-l-o-g-y
I 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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this