473,239 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 software developers and data experts.

how to save a bitmap file from a pictureBox?

Hi,

I using the code below to draw a text in a pictureBox1.

//Start---------------------------------------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
Graphics g;
g = pictureBox1.CreateGraphics();
g.FillRectangle(Brushes.White,0,0,160,160);

Font f = new Font("Arial", 14);

StringFormat format = new StringFormat (StringFormatFlags.NoClip);
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;

g.DrawString("Hello",f,Brushes.Red,40,40,format);
}
//End-------------------------------------------------------------------

My question is how to save the result(it is a "hello" in the pictureBox1) to
a bitmap file.
I mean the bitmap file will contain the "Hello" which i drawed.
thx.
Nov 15 '05 #1
6 61690
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,sizey,g);
bmpsave.Save("C:\\bla.bmp",System.Drawing.Imaging. ImageFormat.Bmp);

hope it helps,

greets

"charsh" <im**@21cn.com> wrote in message
news:ud**************@TK2MSFTNGP12.phx.gbl...
Hi,

I using the code below to draw a text in a pictureBox1.

//Start---------------------------------------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
Graphics g;
g = pictureBox1.CreateGraphics();
g.FillRectangle(Brushes.White,0,0,160,160);

Font f = new Font("Arial", 14);

StringFormat format = new StringFormat (StringFormatFlags.NoClip);
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;

g.DrawString("Hello",f,Brushes.Red,40,40,format);
}
//End-------------------------------------------------------------------

My question is how to save the result(it is a "hello" in the pictureBox1) to a bitmap file.
I mean the bitmap file will contain the "Hello" which i drawed.
thx.

Nov 15 '05 #2
Thanks.

but it doesn't work.
the whole bitmap picture is black. that means nothing inside the bitmap.
"Gerben van Loon" <no****************@home.nl> 写入消息新闻
:bf**********@news1.tilbu1.nb.home.nl...
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,sizey,g);
bmpsave.Save("C:\\bla.bmp",System.Drawing.Imaging. ImageFormat.Bmp);

hope it helps,

greets

Nov 15 '05 #3
Charsh,
If you read Gerben's sample closely he is showing you two things:

How to create a new blank bitmap:
Bitmap bmpsave = new Bitmap(sizex,sizey,g);
How to save a bitmap: bmpsave.Save("C:\\bla.bmp",System.Drawing.Imaging. ImageFormat.Bmp);

What you need now is how to get a bitmap from the Image property of the
Picture box. Unfortunately unless you assign a bitmap to the property it
will remain nothing, even if you draw on the PictureBox.

What I would do is:
- draw on a new bitmap, the first line from Gerben, not the picture box
- assign this bitmap to the image property of the Picture Box
- save this new bitmap

If you are creating a drawing type program, you can use Graphics.DrawImage
to draw the bitmap instead of assigning it to the image property of the
Picture Box.

Hope this helps
Jay

"charsh" <im**@21cn.com> wrote in message
news:OO****************@TK2MSFTNGP10.phx.gbl... Thanks.

but it doesn't work.
the whole bitmap picture is black. that means nothing inside the bitmap.
"Gerben van Loon" <no****************@home.nl> 写入消息新闻
:bf**********@news1.tilbu1.nb.home.nl...
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,sizey,g);
bmpsave.Save("C:\\bla.bmp",System.Drawing.Imaging. ImageFormat.Bmp);

hope it helps,

greets


Nov 15 '05 #4
Not surprising - that code just creates an empty image

Try this fragment

pictureBox1.Image.Save("pictureBox1.bmp",ImageForm at.Bmp);

"charsh" <im**@21cn.com> wrote in message news:<OO**************@TK2MSFTNGP10.phx.gbl>...
Thanks.

but it doesn't work.
the whole bitmap picture is black. that means nothing inside the bitmap.
"Gerben van Loon" <no****************@home.nl> 写入消息新闻
:bf**********@news1.tilbu1.nb.home.nl...
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,sizey,g);
bmpsave.Save("C:\\bla.bmp",System.Drawing.Imaging. ImageFormat.Bmp);

hope it helps,

greets

Nov 15 '05 #5
thanks Jay,

actually, becuase the GDI+ provide a great quality for rotated text.
so i got a rotated text using the following code. but i can not save the
rotated text as a
bitmap file.

//---------------------------------------------------------------------
private void button4_Click(object sender, System.EventArgs e)
{
Graphics g;

g = pictureBox2.CreateGraphics();
g.FillRectangle(Brushes.Gray,0,0,160,160);

Point Middle = new Point (40,40);
g.TranslateTransform (Middle.X, Middle.Y);

g.RotateTransform (45);
Font f = new Font("Arial", 14);

StringFormat format = new StringFormat (StringFormatFlags.NoClip);
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
g.DrawString("I want it",f,Brushes.Red,40,20,format);

}
//------------------------------------------------------------------------

What I would do is:
- draw on a new bitmap, the first line from Gerben, not the picture box
- assign this bitmap to the image property of the Picture Box
- save this new bitmap If you are creating a drawing type program, you can use Graphics.DrawImage
to draw the bitmap instead of assigning it to the image property of the
Picture Box.


I have try the way above, but the question is how to draw a rotated text on
the new bitmap.

i think my question should be : how to save a "text" which i drawed to a
bitmap file?

charsh

Nov 15 '05 #6
charsh,
Do you know how to draw on a bitmap? I neglected to share this with you
yesterday.

Bitmap bmpsave = new
Bitmap(sizex,sizey,System.Drawing.Imaging.PixelFor mat.Format24bppRgbg);
Graphics g; g = Graphics.FromImage(bmpsave );
g.DrawString("I want it",f,Brushes.Red,40,20,format); g.Dispose();

The Graphics.FromImage statement will return a new Graphics object that you
can draw on the bitmap with.

You should always Dispose your Graphics objects that you retrieve outside of
the Paint event. (Graphics you create from CreateGraphics, FromImage, and
the like).

Hope this helps
Jay

"charsh" <im**@21cn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... thanks Jay,

actually, becuase the GDI+ provide a great quality for rotated text.
so i got a rotated text using the following code. but i can not save it as a bitmap file.
//---------------------------------------------------------------------
private void button4_Click(object sender, System.EventArgs e)
{
Graphics g;

g = pictureBox2.CreateGraphics();
g.FillRectangle(Brushes.Gray,0,0,160,160);

Point Middle = new Point (40,40);
g.TranslateTransform (Middle.X, Middle.Y);

g.RotateTransform (45);
Font f = new Font("Arial", 14);

StringFormat format = new StringFormat (StringFormatFlags.NoClip);
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
g.DrawString("I want it",f,Brushes.Red,40,20,format);

}
//------------------------------------------------------------------------

What I would do is:
- draw on a new bitmap, the first line from Gerben, not the picture box
- assign this bitmap to the image property of the Picture Box
- save this new bitmapIf you are creating a drawing type program, you can use Graphics.DrawImageto draw the bitmap instead of assigning it to the image property of the
Picture Box.

I have try the way above, but the question is how to draw a rotated text

on the new bitmap.

i think my question should be : how to save a "text" which i drawed to a
bitmap file?

charsh

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeroen Ceuppens | last post by:
I have the colormap (ARGB, 8bit , so every color from 0 to 255) , put it in an array (1dim) I have the pixel date (array 640x480) What is the best way to make with these array's a bitmap file?...
2
by: Sharon | last post by:
I encountered a strange behavior when doing 鈥榥ew Bitmap鈥: The following code works fine and the given bitmap file is shown on the PictureBox (the m_DrawArea) in the correct bitmap sizes: ...
2
by: madhuri.eerupula | last post by:
Hi Actually my task is to select some text in bitmap file and then copy paste somewhere else may in some word document or notepad or anything. My problem is how to read text from a bitmap file...
9
by: Myombi Natuse | last post by:
I need to print a bitmap file in C under Windows. I'm a senior in college so please show me the respect I'm due. I don't want any of you jokers telling me that it can't be done because I know it...
1
by: =?Utf-8?B?VmVuZWRpY3Q=?= | last post by:
Hi All, I have few encrypted bitmap file. The original source program for encrypting those bitmap is no longer exists. FYI, the original program to encrypt those images is writing in DOS. Now...
1
by: prashanthaputta | last post by:
Hello All, I am Developing a MFC SDI application,where I want to store the CHtmlView Contents as Bitmap Image file.I have made CHtmlView as a Child of CView.I want to create this bitmap file...
1
by: prashanthaputta | last post by:
Hello All, I am Developing a MFC SDI application,where I want to store the CHtmlView Contents as Bitmap Image file.I have made CHtmlView as a Child of CView.I want to create this bitmap file...
5
by: stef | last post by:
hello I can find all kind of procedures to convert an array to a bitmap (wxPython, PIL), but I can't find the reverse, either - convert a bitmap to an array or - read a bitmap file to an...
1
hi
by: milayaraja | last post by:
How to save bitmap image into postgreSQL this is my id........
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you抣l learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.