General C# question

Nachtwind

11-10-2005 15:39:52

Does someone here know how to paint a simple picture? All i need to do is make a picture of about 700x700 Pixels with black background and at given positions some white dots.

I tried to to it with the following function but the result was - nothing. All i had afterwards was the Picture i had before..


private void paintStar (double x, double y)
{
Bitmap myBitmap = new Bitmap(@"C:\test.bmp");
Graphics g = Graphics.FromImage(myBitmap);
Pen myPen = new Pen(Color.White);
myPen.Width = 2;
// Pic 700*700; Origin 0:0 = 350:350
float xn, yn;
xn = (float) (x*350);
yn = (float) (y*350);
g.DrawPie(myPen, xn,yn,3,3,0,359);
g.Save();
}

l33ts0n

11-10-2005 20:11:20

This is probably the wrong forum for it.

Forum / site.

Anyway: its myBitmap.Save()

Graphics.Save() saves the graphics state... that's for some pretty advanced stuff.

SphericalByte

11-10-2005 20:17:54



private void paintStar (double x, double y)
{
Bitmap myBitmap = new Bitmap(@"C:\test.bmp");
Graphics g = Graphics.FromImage(myBitmap);
Pen myPen = new Pen(Color.White);
myPen.Width = 2;
// Pic 700*700; Origin 0:0 = 350:350
float xn, yn;
xn = (float) (x*350);
yn = (float) (y*350);
g.DrawPie(myPen, xn,yn,3,3,0,359);
g.Save();
}


Even though your code is not that optimal, it's not wrong either. I think there is just some misunderstanding of what you are doing.

I did the following in a class i derived from Panel:

protected override void OnPaint(PaintEventArgs e)
{
float x = 0.5f;
float y = 0.5f;

// Bitmap myBitmap = new Bitmap(@"C:\test.bmp");
Graphics g = e.Graphics;//Graphics.FromImage(myBitmap);
Pen myPen = new Pen(Color.Black);
myPen.Width = 2;
// Pic 700*700; Origin 0:0 = 350:350
float xn, yn;
xn = (float) (x*350);
yn = (float) (y*350);
g.DrawPie(myPen, xn, yn, 3, 3, 0, 359);
g.Save();
}

This does draw a small dot (You might want to try DrawEllipse() instead of DrawPie though).
But i think what you really wanted to do is change the bitmap("test.bmp") and save to that file afterwards.
Instead you created a Bitmap in memory (Bitmap myBitmap = new Bitmap(@"C:\test.bmp");).
Then you initialised a toolset for graphics manipulation (Graphics g = Graphics.FromImage(myBitmap);) and drew to the bitmap.
Then you saved the state of the Graphics-object(g.Save();) - again all in memory - note that Graphics.Save() returns a GraphicsState object. I guess that you wanted to save the file, which you do by calling Bitmap.Save(string fileName).
Imo the concept of the Graphics object is not really intuitive, but well.. it is that way.

If that is not what you wanted to do, please explain what the intention of paintStar() is.

Edit: Beaten :o - I agree that this is propably not the right place at all to ask things like that.

Nachtwind

12-10-2005 13:59:00

well, i agree, that this is not the right place, but this is the only C# Board i know where the people are not that arrogant, that they aren't answering questions at all. Anyway, thank you for the help :)