By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

Multiple when changing quality

P: n/a
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"

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

bob.Save(file, ico, p)
}catch(System.Runtime.InteropServices.ExternalExce ption ex)
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 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
Share this Question
Share on Google+
1 Reply

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.