dinoboy Posted October 11, 2003 Posted October 11, 2003 Hi! I generate thumbnails dynamically. The function has two parameters - filename and maxfilesize. And while thumbnail size in butes is bigger than the maxfilesize, it make new thumbnail again, only a smaller one. And my problem is how I can check the thumbnail size? It tried to save it to stream and then I took its length and compared it with maxfilesize and do the while loop. But when I tried to make a new bitmap with a new size, in the loop, then it told me The invalid parameter used Are there any other solution or why it tells it? Quote
dinoboy Posted October 12, 2003 Author Posted October 12, 2003 public void OutputFile(string fileName, int maxThumbSize) { System.Drawing.Image g = System.Drawing.Image.FromFile(fileName); ImageFormat tFormat = g.RawFormat; Size tSize = this.genThumbSize((int) g.Width, (int) g.Height); Bitmap imgOutPut = new Bitmap(g, tSize.Width, tSize.Height); MemoryStream imgStream = new MemoryStream(); imgOutPut.Save(imgStream, tFormat); //imgOutPut.Dispose(); while(imgStream.Length>maxThumbSize) { this.thumbSize = this.thumbSize-5; Size s = this.genThumbSize(imgOutPut.Width, imgOutPut.Height); imgOutPut = new Bitmap(System.Drawing.Image.FromFile(fileName), s.Width, s.Height); imgOutPut.Save(imgStream, tFormat); } //imgOutPut.Palette = if(tFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif)) Response.ContentType = "image/gif"; else if(tFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp)) Response.ContentType = "image/bmp"; else if(tFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg)) Response.ContentType = "image/jpeg"; else if(tFormat.Equals(System.Drawing.Imaging.ImageFormat.Png)) Response.ContentType = "image/png"; imgOutPut.Save(this.Response.OutputStream, tFormat); } This line gives me the Invalid parameter imgOutPut = new Bitmap(System.Drawing.Image.FromFile(fileName), s.Width, s.Height); Wihtout the while loop, it's all ok, working just fine... Quote
aewarnick Posted October 13, 2003 Posted October 13, 2003 (edited) Try putting the Image.FromFile in it's own Bitmap variable. Bitmap b= (Bitmap)Image.FromFile(fileName); imgOutPut = new Bitmap(b, s.Width, s.Height); Edited October 13, 2003 by aewarnick Quote C#
dinoboy Posted October 13, 2003 Author Posted October 13, 2003 (edited) I did that in while loop and before the while, but no use, it told me again Inavalid parameter used. :( Hmm, maybe is there some problem with parameter nulling? or something :S Edited October 13, 2003 by dinoboy Quote
aewarnick Posted October 13, 2003 Posted October 13, 2003 I think it would give a null reference exception. But you can check each parameter before it is used in the method: if(bitmap != null && imgOutPut != null) { if(imgOutPut.Width > 0 && imgOutPut.Height > 0) { do code } } Quote C#
dinoboy Posted October 14, 2003 Author Posted October 14, 2003 Hmm, it seems it don't help me. Because parameters have a values and not null. But still it is saying that.. :S There are some problem with while loop but I don't know which :confused: Quote
aewarnick Posted October 14, 2003 Posted October 14, 2003 What kind of error is this? A runtime error or a compile error? Quote C#
dinoboy Posted October 15, 2003 Author Posted October 15, 2003 Thanks for the replys. But I already found a solution. I saved the temporary stream to a temp fail and then read it again and got the length and then deleted the file. And it's working :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.