473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compress an JPEG file wtih high quality?

Hi everyone, this should be a quick question.
I am writing a function to compress the Jpeg file,with
the API Image.Save(...) .

the code as follow that:

public static void Save(string imagePath, Bitmap image, int quality)
{
if (JpegQuality.Co dec == null)
image.Save(imag ePath,
System.Drawing. Imaging.ImageFo rmat.Jpeg);
else
{
EncoderParamete rs ep = new EncoderParamete rs();
ep.Param[0] = new
EncoderParamete r(System.Drawin g.Imaging.Encod er.Quality, quality);
image.Save(imag ePath, JpegQuality.Cod ec, ep);
ep.Dispose();
}
}

But use this function,the compressed photo would lost so much
info. e.g.:when a originality is about 1.5M large,
the compress result would get a file only about 30K(set the quality
gene as 85)

How could i compree a file larger than 1.5M to about only 1M?
Thanks!

Nov 6 '06 #1
1 11532
Is anyone kown how to fix it?
On Nov 6, 5:24 pm, ironpythons...@ gmail.com wrote:
Hi everyone, this should be a quick question.
I am writing a function to compress the Jpeg file,with
the API Image.Save(...) .

the code as follow that:

public static void Save(string imagePath, Bitmap image, int quality)
{
if (JpegQuality.Co dec == null)
image.Save(imag ePath,
System.Drawing. Imaging.ImageFo rmat.Jpeg);
else
{
EncoderParamete rs ep = new EncoderParamete rs();
ep.Param[0] = new
EncoderParamete r(System.Drawin g.Imaging.Encod er.Quality, quality);
image.Save(imag ePath, JpegQuality.Cod ec, ep);
ep.Dispose();
}
}

But use this function,the compressed photo would lost so much
info. e.g.:when a originality is about 1.5M large,
the compress result would get a file only about 30K(set the quality
gene as 85)

How could i compree a file larger than 1.5M to about only 1M?

Thanks!
Nov 7 '06 #2

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

Similar topics

9
3207
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is indeed also true for our language of choice, Python. Its file type allows some extraordinary convenient access like: for line in open("blah"): handle_line(line)
11
2499
by: Shiperton Henethe | last post by:
Dreamweaver 4 Hi Can anyone recommend a decent utility for compressing HTML that is safe - i.e. that *definitely* doesn't mess with the appearance in any browsers. I run a growing website whose pages are inexorably getting too "heavy".
10
19531
by: Ryan Cooper | last post by:
Can anyone give me an idea or better yet, a code sample, demonstrating how to parse a JPEG header and search the header for markers located in the stream? Basically, I need to analyze an uploaded JPEG file, search for the markers C2, C6 and CA in the stream, and then set a variable of some sort to specify whether or not these markers are present. (The reason I need these is to determine whether the JPEG is in "Progressive" or "Baseline"...
5
11684
by: Jigar Mehta | last post by:
Hye Friends!!, Happy New Year!! I am Jigar Mehta from India. Currently I am working on a project in which I need to compress some images on the harddisk... I want to make an engine that reads whole BMP image and then compress it.. The target location can be of any type.. BMP, TIFF, JPG or any.. Some data loss will be negligible because all the images are having very high resolution with 32-bit colors (taken from digi-cam).
10
11062
by: rtilley | last post by:
Hope it's not inappropriate to post this here. Could someone critique my code? I have no Python programmers in my office to show this to. The script works OK, but should I do it differently? I especially don't like how I check to see if jpegs exist. The style may not be acceptable to some, but I'm concerned with substance, not style. Is there a 'more appropriate' way to do this? Thanks to all who take the time to give advice!
1
7832
by: Smokey Grindel | last post by:
I have a bitmap object I want to return as a JPEG image with a compression set at 90% and progressive passes enabled, how can I do this in .NET 2.0? Progressive passes are not necessary but the compression ratio is.. thanks!
4
3820
by: Greg | last post by:
I've searched everywhere for a solution Microsoft .NET Framework V 2.0.50727 AutoEventWireup="false" image2.aspx resize an image on the fly but Page_Load is triggered twice: Any suggestion? Here is the code behind:
5
6393
by: jayharvard1 | last post by:
Hello All. I'm trying to create jpegs out of data that is stored in a binary blob format in an RDBMS (MS Access). I've tried writing the jpeg directly: while not rs.EOF: op = file(imgdir + "\\" + pic,"w") print >op, rs.Fields.Value ##where rs.Fields.Value is the data in the blob from Access. When I try to write out this file, the jpeg doesn't turn out.
2
9372
by: Zuhaib Hyder | last post by:
string stFileName = "abc"; string stFullFilePath = Server.MapPath("images/" + stFileName + ".jpg"); System.Drawing.Image i = System.Drawing.Image.FromFile(stFullFilePath); EncoderParameters eps = new EncoderParameters(1); eps.Param = new EncoderParameter( Encoder.Quality, 40 ); ImageCodecInfo ici = GetEncoderInfo("image/jpeg");//this line give error, "The name 'GetEncoderInfo' does...
0
9685
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
9533
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,...
1
10190
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
10019
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
5447
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
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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.