May 1st, 2009 | No Comments

The following code converts any image format,

public void ConvertImage2Jpeg(string input, string output)
{
try
{
ImageCodecInfo myimagecodeinfo;
string inputpath;
string outputpath = output;
string format;
inputpath = input;
format = inputpath.Substring(inputpath.LastIndexOf(".") + 1);

if (format == "tif")
{
myimagecodeinfo = GetEncoderInfo("image/tiff");

}
else
{
myimagecodeinfo = GetEncoderInfo("image/" + format);

}
EncoderParameters eparam = new EncoderParameters(1);
EncoderParameter encparam;
System.Drawing.Imaging.Encoder enc;
enc = System.Drawing.Imaging.Encoder.Transformation;
encparam = new EncoderParameter(enc, (long)EncoderValue.TransformRotate90);
eparam.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 10L);
string jpg;
Image img;
img = Image.FromFile(inputpath);
jpg = outputpath.Substring(0, outputpath.LastIndexOf("\\") + 1) + Path.GetFileNameWithoutExtension(inputpath) + ".JPG";
img.Save(jpg, myimagecodeinfo, eparam);

}
catch (Exception exp)
{

}

}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}

Written by Ajay Matharu

May 1st, 2009 at 11:34 pm

Apr 4th, 2009 | No Comments

While working on the project we came across a problem that, we were not able to read value of read only text box, i.e. TextBox1.Text returned nothing even when the text box had value.

On googling, I found after doing this you can make your text box read only and also it will return the value of the text box. You need to insert this line on your Page_Load

TextBox1.Attributes.Add(“readonly”, “true”);

Written by Ajay Matharu

April 4th, 2009 at 5:37 pm