View previous topic :: View next topic |
Author |
Message |
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Tue Aug 07, 2007 5:10 pm Post subject: new Bitmap |
|
|
Sorry to ask such a simple question, but how do you create a new "Blank" bitmap. I don't see a constructor that appears to do the job. I want a Bitmap that I can use as a buffer for my PictureBox, but I want to start with a blank image instead of loading one from a file.
Thanks,
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Wed Aug 08, 2007 12:14 pm Post subject: Re: new Bitmap |
|
|
MemoryGraphics gives you a Graphics that is backed by a bitmap, which you can draw on and then copyTo something else.
I made a GraphicsBuffer addon that might give some insight. |
|
Back to top |
|
|
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Wed Aug 08, 2007 2:44 pm Post subject: |
|
|
Thanks for the help so far, but I still have some problems. It is possible that you have turned me in the right direction and that I just don't see it. I have more of a C# background and what my problem amounts to is that I want to implement a similar drawing scenario as the code demonstrates below (in psuedo C#).
Code: | private Bitmap bmp;
private PictureBox picBox;
private Graphics g;
public void init()
{
bmp = new Bitmap(200,200);
g = Graphics.FromImage(bmp);
//skipping most of picBox setup for cause just an example
picBox.Image = bmp;//set image that picBox will use
}
private void picBox_onSomeCoolEvent(Object sender, EventArgs ea)
{
Pen p = new Pen(Color.Black);//Create a pen
g.DrawLine(p, x1, y1, x2, y2);//draw to the image (bmp)
picBox.Image = bmp;//update the picBox image to be painted
} |
I am happy to see that most of DFL is very similar to C#.NET GUI coding, but that is also the very thing that gets me into trouble. Gets confusing at times.
Thanks for your time and efforts,
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Sat Aug 11, 2007 5:18 pm Post subject: |
|
|
I just put up a snapshot that lets you get a Bitmap from a MemoryGraphics.
The way to use it is slightly different from the code you showed...
g = new MemoryGraphics(200, 200);
g.drawLine(p, x1, y1, x2, y2);
picBox.image = g.toBitmap();
Note that MemoryGraphics.toBitmap is a trial feature and could be removed. |
|
Back to top |
|
|
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Sat Aug 11, 2007 5:49 pm Post subject: |
|
|
Thanks a lot. In some ways, this works out better than the c# implementation.
Laters,
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
|