473,385 Members | 1,357 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,385 software developers and data experts.

Question: Load bmp and save as jpg

I want to convert one bitmap file to another one.
For example load as bmp and save as jpg.
The loading part is simple I do this:

Stream BitmapStream =
File.Open(sSrcFile,FileMode.Open,FileAccess.Read,F ileShare.None);
Bitmap imgPhoto=new Bitmap(BitmapStream);
iPixelsX=imgPhoto.Width;
iPixelsY=imgPhoto.Height;
BitmapStream.Close();

The saving will be something like this; but I fail to see how I can hook up
imgPhoto from the load to this stream.:

Stream DestBitmapStream =
File.Open(DstFile,FileMode.CreateNew,FileAccess.Wr ite,FileShare.None);
// how do I connect imgPhoto?
DestBitmapStream.Close();

Also I wonder if the Pixelfomat is different, lest say I load 8 bit indexed
color palette bitmap and want to save as 24 bit RGB jpeg, could this be done
automatic?
Something tells me that I need to copy the bytes manually??? I hope not.

Many thanks.

Olaf
Nov 17 '05 #1
2 4086
how about:

....
Size size = new Size(iPixelsX=imgPhoto.Width, iPixelsY=imgPhoto.Height);

Image sourceImage = Image.FromFile("c:\\test.bmp");
Bitmap bitmap = new Bitmap(sourceImage, size);
bitmap.Save("C:\\test.jpeg", ImageFormat.Jpeg);

bitmap.Dispose();
sourceImage.Dispose();

Check out Bob Powell's website for more on GDI+ etc...

http://www.bobpowell.net/gdiplus_faq.htm

HTH

Ollie Riches

"Olaf Baeyens" <ol**********@skyscan.be> wrote in message
news:43***********************@news.skynet.be...
I want to convert one bitmap file to another one.
For example load as bmp and save as jpg.
The loading part is simple I do this:

Stream BitmapStream =
File.Open(sSrcFile,FileMode.Open,FileAccess.Read,F ileShare.None);
Bitmap imgPhoto=new Bitmap(BitmapStream);
iPixelsX=imgPhoto.Width;
iPixelsY=imgPhoto.Height;
BitmapStream.Close();

The saving will be something like this; but I fail to see how I can hook
up
imgPhoto from the load to this stream.:

Stream DestBitmapStream =
File.Open(DstFile,FileMode.CreateNew,FileAccess.Wr ite,FileShare.None);
// how do I connect imgPhoto?
DestBitmapStream.Close();

Also I wonder if the Pixelfomat is different, lest say I load 8 bit
indexed
color palette bitmap and want to save as 24 bit RGB jpeg, could this be
done
automatic?
Something tells me that I need to copy the bytes manually??? I hope not.

Many thanks.

Olaf

Nov 17 '05 #2
Hi Ollie,

That simple? :-)
Many thanks I will check into this.... :-)

how about:

....
Size size = new Size(iPixelsX=imgPhoto.Width, iPixelsY=imgPhoto.Height);
Image sourceImage = Image.FromFile("c:\\test.bmp");
Bitmap bitmap = new Bitmap(sourceImage, size);
bitmap.Save("C:\\test.jpeg", ImageFormat.Jpeg);

bitmap.Dispose();
sourceImage.Dispose();

Check out Bob Powell's website for more on GDI+ etc...

http://www.bobpowell.net/gdiplus_faq.htm

Nov 17 '05 #3

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

Similar topics

2
by: Matthias S. | last post by:
Hi, I have to write an application which extensively uses an SQL Database. For a simple example say I have the following tables with the appropriate fields. 1. Company (ID, Name,...
0
by: NWx | last post by:
Hi, I discovered a strange (?!?!) issue related objects saved to cache. Let's explain my situation. I have a webform for user registration. Users enter username, password and other info...
3
by: Debbie Carter | last post by:
Can XML files be easily encrypted?
1
by: Tom | last post by:
I have a large application; lots of forms, multiple dynamic DLLs, etc. I also have, in the appliation, a general 'Preferences' class object (which is in itself a separate DLL, and I just include a...
13
by: ^MisterJingo^ | last post by:
I've been reading up on interfaces, one example I came across showed that you can hide a method implemented from an interface from the class which implements it. To use it, you must cast to the...
9
by: Tanja Krammer | last post by:
Hi, I see System.Windows.Forms.SaveFileDialog but no LoadFileDialog. How do I make button text to "Load" instead of "Save" Thank you
10
by: Nemisis | last post by:
HI everyone, I think i am on the right path but if someone could confirm it, that would be great. In my business Layer i have my business object, for this example, called User. User has...
13
by: John Kraft | last post by:
Friends, I'm working on some crud stuff, and I was looking for opinions on the subject. Below, I have pasted some VERY simple sample code. Class2 is a "traditional" crud type object. In a...
29
by: Brad Pears | last post by:
Here is a simple OO design question... I have a Contract class. The user can either save an existing contract or they start off fresh with a blank contract, fill in the data and then save a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.