473,666 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

save image

Hello

I want to save a image to specified path as a jpg format.
But I'm getting some error messages.

Codes are shown below ;

path ="C:\\image.jpg ";
FileStream fs = new FileStream(path ,FileMode.Creat e,FileAccess.Wr ite);
MemoryStream ms = new MemoryStream();
i.Save(ms,Image Format.Jpeg);
byte[] b = new byte[ms.Length];
ms.Write(b,0,b. Length);
fs.Write(b,0,b. Length);
fs.Close();

i is image object,it was loaded from anywhere(from path or database),
We suppose that size of i object is 223 kb and after codes mentioned above a
image is saved and it's size is 223kb but,picture in the saved file is not
appear.

i object is load with codes below;

String path;
Stream myStream;
OpenFileDialog openFileDialogP icture = new OpenFileDialog( );
openFileDialogP icture.InitialD irectory = "C:\\temp\\imag e.jpg";
openFileDialogP icture.Filter = "picture files (*.jpg)|*.jpg";
openFileDialogP icture.FilterIn dex = 2 ;
openFileDialogP icture.RestoreD irectory = true ;
if(openFileDial ogPicture.ShowD ialog() == DialogResult.OK )
{
if((myStream = openFileDialogP icture.OpenFile ())!= null)
{
path = openFileDialogP icture.FileName ;
Image i = Image.FromFile( path);
}
}

finally,How can I save this image object to specified path.

Thanks.
Nov 17 '05 #1
1 22831
Hi Brenny,

If you just want to copy this file to another location I would recommend using File.Copy instead of saving it again since that would just create a slightly lower quality JPG than you had to begin with.

In any case, to save an Image as JPG just use
Image.Save(path , ImageFormat.Jpe g);

Btw, when you say you get error message it helps if you tell us the exact errors (copy/paste).
--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2

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

Similar topics

4
8724
by: jack | last post by:
Hi. I wanted to save image from the form in my accss database. there is one picture box on form which loads the picture from the harddisk . i want this picture to store in my database .. thanks for the help..
4
3729
by: Hrvoje Vrbanc | last post by:
I would like to know the most efficient way to copy an image from an Internet URL to the local hard disk by means of using an ASP.NET page. So, I would like to click the button on the ASP.NET page and thus to save a copy of a picure at let's say http://www.blabla.com/pic.jpg to predefined location on my hard disk. Thanks in advance, Hrvoje
1
1345
by: chandan | last post by:
Hi, I am in search of a control that can save image form my webpage. On that web page I am using my own context menu and I disabled the default context menu of IE. Now I want the same functionality as given by IE context menu item save Image as! So tell me how IE works in that case?? Which API or function calls IE when clicking on their context menu Item Save Image As..?
0
2526
by: hnpatel | last post by:
hello friends, i m making application in vb.NET. i m using MY SQL 5.0 and vs 2005 for this application. Now I want to save image file in sql database. i m using blob datatype of image field. i want to save image file from vb.net form. i m getting image in picturecontrol through openfiledialogbox. now how to save this image in my database through insert query? Plz help me for this..... Thanx in advance.....
6
4029
by: Jerry Spence1 | last post by:
I am using a network camera that saves the image in a byte array in memory (via their ocx component, and in the OnNewImage event I can get the pointer to the image and the byte length as e.lFrmBytes e.lPtrToImage How do I get at that array in memory and save it to disk? It seems to suggest a pointer which is not supported in VB.
1
2867
ranjana1980
by: ranjana1980 | last post by:
In my project of desktop application using c#.net save image in database during registration of student But it is not mandatory.Without Browse the image i click on insert button it gives error "Empty path name is not legal". con.ConnectionString = "Data Source=XPO3;Initial Catalog=Imsapplication;Integrated Security=True"; con.Open(); //Cryclass cc = new Cryclass(); string filepath = textBox2.Text; ...
2
9656
by: rajeshkumarswain | last post by:
hi friends, I am new in php and i am trying to save image to database. Please provide a sample.
3
2011
by: regan2007 | last post by:
How are you going to save image in database using php?Please explain it if you do kno
1
2786
by: sushant191 | last post by:
Hi Everyone , can any one tell me, how to save image url path in variable using fckeditor built-in image browser for ex.(~/userfiles/image1.jpg). I m not uploading image from outside fckeditor. Pls Help Me!!!!!! Thanks in advance.
2
7476
by: aznimah | last post by:
Hi, i need help on how to save the image that return from picturebox? basically the program works, 1)Read image (.png)--> load into pictureBox1 2)Fire button save to save the image from pictureBox1 Here i place code:
0
8444
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’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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
5664
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.