473,405 Members | 2,171 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,405 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 61712
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 ‘new 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.