This is a migrated thread and some comments may be shown as answers.

[Solved] Pls help! urgent

0 Answers 14 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
temesgen
Top achievements
Rank 1
temesgen asked on 29 Dec 2012, 08:35 AM
I cant upload images to the application
here is the code i am currently with


public

 

 

static void ImageResize(byte[] data, string desPath, int thumbWidth, int thumbHeight, long quality)

 

{

 

 

Stream stream = new MemoryStream(data);

 

 

 

var sourceBitmap = new Bitmap(stream);

 

 

 

var thumbBitmap = new Bitmap(thumbWidth, thumbHeight);

 

 

 

var g = Graphics.FromImage(thumbBitmap);

 

 

 

try

 

{

g.InterpolationMode =

 

InterpolationMode.HighQualityBicubic;

 

g.FillRectangle(

 

Brushes.White, 0, 0, thumbWidth, thumbHeight);

 

g.DrawImage(sourceBitmap, 0, 0, thumbWidth, thumbHeight);

 

 

var info = ImageCodecInfo.GetImageEncoders();

 

 

 

var param = new EncoderParameters(1);

 

param.Param[0] =

 

new EncoderParameter(Encoder.Quality, quality);

 

 

 

string folderToUp = desPath.Substring(0, desPath.LastIndexOf("/") + 1);

 

 

 

try

 

{

 

 

if (Directory.Exists(folderToUp) == false)

 

{

 

 

Directory.CreateDirectory(folderToUp);

 

}

}

 

 

catch

 

{

}

thumbBitmap.Save(desPath, info[1], param);

}

 

 

finally

 

{

sourceBitmap.Dispose();

thumbBitmap.Dispose();

g.Dispose();

}

}

let me know the flaws of the code too

Tags
General Discussions
Asked by
temesgen
Top achievements
Rank 1
Share this question
or