473,890 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(o bject sender, System.EventArg s e)
{
Graphics g;
g = pictureBox1.Cre ateGraphics();
g.FillRectangle (Brushes.White, 0,0,160,160);

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

StringFormat format = new StringFormat (StringFormatFl ags.NoClip);
format.Alignmen t = StringAlignment .Center;
format.LineAlig nment = StringAlignment .Center;

g.DrawString("H ello",f,Brushes .Red,40,40,form at);
}
//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 61796
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,si zey,g);
bmpsave.Save("C :\\bla.bmp",Sys tem.Drawing.Ima ging.ImageForma t.Bmp);

hope it helps,

greets

"charsh" <im**@21cn.co m> wrote in message
news:ud******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

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

//Start---------------------------------------------------------------
private void button1_Click(o bject sender, System.EventArg s e)
{
Graphics g;
g = pictureBox1.Cre ateGraphics();
g.FillRectangle (Brushes.White, 0,0,160,160);

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

StringFormat format = new StringFormat (StringFormatFl ags.NoClip);
format.Alignmen t = StringAlignment .Center;
format.LineAlig nment = StringAlignment .Center;

g.DrawString("H ello",f,Brushes .Red,40,40,form at);
}
//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**********@n ews1.tilbu1.nb. home.nl...
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,si zey,g);
bmpsave.Save("C :\\bla.bmp",Sys tem.Drawing.Ima ging.ImageForma t.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,si zey,g);
How to save a bitmap: bmpsave.Save("C :\\bla.bmp",Sys tem.Drawing.Ima ging.ImageForma t.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.DrawIm age
to draw the bitmap instead of assigning it to the image property of the
Picture Box.

Hope this helps
Jay

"charsh" <im**@21cn.co m> wrote in message
news:OO******** ********@TK2MSF TNGP10.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**********@n ews1.tilbu1.nb. home.nl...
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,si zey,g);
bmpsave.Save("C :\\bla.bmp",Sys tem.Drawing.Ima ging.ImageForma t.Bmp);

hope it helps,

greets


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

Try this fragment

pictureBox1.Ima ge.Save("pictur eBox1.bmp",Imag eFormat.Bmp);

"charsh" <im**@21cn.co m> wrote in message news:<OO******* *******@TK2MSFT NGP10.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**********@n ews1.tilbu1.nb. home.nl...
Hi,

Would be something like this:

Bitmap bmpsave = new Bitmap(sizex,si zey,g);
bmpsave.Save("C :\\bla.bmp",Sys tem.Drawing.Ima ging.ImageForma t.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(o bject sender, System.EventArg s e)
{
Graphics g;

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

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

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

StringFormat format = new StringFormat (StringFormatFl ags.NoClip);
format.Alignmen t = StringAlignment .Center;
format.LineAlig nment = StringAlignment .Center;
g.DrawString("I want it",f,Brushes.R ed,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.DrawIm age
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,si zey,System.Draw ing.Imaging.Pix elFormat.Format 24bppRgbg);
Graphics g; g = Graphics.FromIm age(bmpsave );
g.DrawString("I want it",f,Brushes.R ed,40,20,format ); g.Dispose();

The Graphics.FromIm age 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.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.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(o bject sender, System.EventArg s e)
{
Graphics g;

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

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

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

StringFormat format = new StringFormat (StringFormatFl ags.NoClip);
format.Alignmen t = StringAlignment .Center;
format.LineAlig nment = StringAlignment .Center;
g.DrawString("I want it",f,Brushes.R ed,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.DrawIm ageto 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
2563
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? Thx Jeroen
2
3034
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: private Graphics m_gMapImg; private Bitmap m_backroundImage; private Bitmap MapImg; private PictureBox m_DrawArea;
2
5778
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 (hand written document) using c#. Actually how to select particular text in a bitmap file and show it somewhere else using c#. Are there any commands to do directly. I am planning to find pixel position from bmp file and from those positions to...
9
5208
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 can. Post the code here no later than Friday by noon, please. I'm counting on you guys to come through. I really need this. Benefits for those that help. I have more money and friends than most if not all of you could ever dream of. Thx in...
1
2014
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 I need to decrypt those image file in C#. Is there anyway that I can do to decrypt those images? Any advice is much appreciated.
1
2138
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 when an button on the popup dialog is clicked.I want entire content of CHtmlView even though the poppup dialog is above the CHtmlView. Please tell me how to Implement this..I need it urgently..
1
1617
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 when an button on the popup dialog is clicked.I want entire content of CHtmlView even though the poppup dialog is above the CHtmlView. Please tell me how to Implement this..I need it urgently..
5
9106
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 array
1
2811
hi
by: milayaraja | last post by:
How to save bitmap image into postgreSQL this is my id........
0
9976
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we抣l explore What is ONU, What Is Router, ONU & Router抯 main usage, and What is the difference between ONU and Router. Let抯 take a closer look ! Part I. Meaning of...
1
10903
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10449
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8006
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7158
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5834
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6034
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4659
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4257
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.