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

Multiple image.save() when changing quality

i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of what the image looks like, and how big it is. the quality is selected using a trackBar1. the MouseUp event of trackBar1 triggers this method

public void updatePanel()
string file = System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssembly().Location) + "\\jpg.temp"

//sav
ImageCodecInfo ico = GraphicsTools.getEncoderInfo("image/jpeg")
Encoder qualityEncoder = Encoder.Quality
EncoderParameter ratio = new EncoderParameter(qualityEncoder, quality)
EncoderParameters p = new EncoderParameters(1)
p.Param[0] = ratio

try
bob.Save(file, ico, p)
}catch(System.Runtime.InteropServices.ExternalExce ption ex)
Console.WriteLine(ex.Message)
//loa
panel2.BackgroundImage = Image.FromFile(file)
FileInfo fi = new FileInfo(file)
textBox1.Text = ((int)(fi.Length/1024)).ToString() + "KB"
'bob.Save(file, ico, p)' throws an 'ExternalException', but only from the second time this method is called - never the first. i can put multiple image.save calls in this method, and have them all work the first time this method is called. how do i need to change this code to allow me to save multiple times, at any quality, to the same location?
Jul 21 '05 #1
1 2117
addendum

i solved this problem by saving to 'System.IO.Path.GetDirectoryName(System.Reflection .Assembly.GetExecutingAssembly().Location) + "\\temp\\" + quality.ToString() + ".temp";'

using a different filename for each quality got around the problem, but it created a lot of tmepory files that need deleting. there has to be a better way

Jul 21 '05 #2

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

Similar topics

3
by: Zahid Khan | last post by:
I need little help in my situation. I am reading a graphic file (jpg) from disk and then resizing it and save resized image. What happens, it gets blured, I want to retain same quality so that...
2
by: Travis | last post by:
Hi everyone, I'm using the System.Drawing.Imaging.Bitmap to retrieve and modify the metadata tags (user comments, keywords etc) of JPEGS. I was wondering if changing these tags in any way...
6
by: Chris D | last post by:
Hi, I have an application where a user uploads an image and I create two thumbnails. One a small image and the second is a larger image but still smaller then the original. I store these in SQL...
7
by: somequestion | last post by:
System.Drawing.Image newImage = Bitmap(....) newImage.Save(destinationPath, ImageFormat.Jpeg); this image resolution is very low i'd like to make high quality image so i change...
6
by: Michael | last post by:
I'm trying to use the Bitmap class's Save Method to save a Bitmap as a GIF. My code runs fine, and converts the image, but the quality is not anywhere close to as good. I know that GIF quality is...
1
by: Sean | last post by:
i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of...
1
by: Daniel Mark | last post by:
hello all: I am using Image module from PIL to save created image as JPG format. Is there any option I could set for function Image.save so that the stored image will have the highest quality....
9
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to...
8
by: JJ | last post by:
Whilst I am resizing images I am losing quality. This is only happening in small amounts, but if you repeatedly put the same image through the following code, the image quality slowly degrades. Can...
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
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.