473,753 Members | 7,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sSrcF ile,FileMode.Op en,FileAccess.R ead,FileShare.N one);
Bitmap imgPhoto=new Bitmap(BitmapSt ream);
iPixelsX=imgPho to.Width;
iPixelsY=imgPho to.Height;
BitmapStream.Cl ose();

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 DestBitmapStrea m =
File.Open(DstFi le,FileMode.Cre ateNew,FileAcce ss.Write,FileSh are.None);
// how do I connect imgPhoto?
DestBitmapStrea m.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 4099
how about:

....
Size size = new Size(iPixelsX=i mgPhoto.Width, iPixelsY=imgPho to.Height);

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

bitmap.Dispose( );
sourceImage.Dis pose();

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

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

HTH

Ollie Riches

"Olaf Baeyens" <ol**********@s kyscan.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(sSrcF ile,FileMode.Op en,FileAccess.R ead,FileShare.N one);
Bitmap imgPhoto=new Bitmap(BitmapSt ream);
iPixelsX=imgPho to.Width;
iPixelsY=imgPho to.Height;
BitmapStream.Cl ose();

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 DestBitmapStrea m =
File.Open(DstFi le,FileMode.Cre ateNew,FileAcce ss.Write,FileSh are.None);
// how do I connect imgPhoto?
DestBitmapStrea m.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=i mgPhoto.Width, iPixelsY=imgPho to.Height);
Image sourceImage = Image.FromFile( "c:\\test.bmp") ;
Bitmap bitmap = new Bitmap(sourceIm age, size);
bitmap.Save("C: \\test.jpeg", ImageFormat.Jpe g);

bitmap.Dispose( );
sourceImage.Dis pose();

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
2903
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, AddresseInfoID) 2. AddresseInfo (ID, Street, City, Zip) (Those two obviously have a relationship)
0
1114
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 Username must be unique, obviously, and this is enforced at database level, with a unique index on username field. I use a BO object to save / load data from database. This BO uses a DataRow
3
1587
by: Debbie Carter | last post by:
Can XML files be easily encrypted?
1
1631
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 reference to it so I can instantiate it at the beginning) which stores all my user preferences. I serialize the data to and from an XML file, thereby saving and restoring the user preferences with ease. I also have a Preferences form that the user...
13
1764
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 interface type e.g.: interface IFoo { void display(); }
9
1348
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
1388
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 about 50 properties.
13
2711
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 real example, these objects would probably implement some kind of ICrud interface with the common methods. I'm finding that many times, though, I want to use these objects as simple data objects, and I don't need all the database functionallity.
29
2226
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 "new" contract. I have a method in my contract class called "Save" which is called like this... dim oContract as new Contract
0
9072
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
9653
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
9333
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...
0
8328
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6869
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
6151
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
4771
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...
1
3395
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
3
2284
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.