Click here to Skip to main content
15,894,907 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionQuerystring issue Pin
bhavnvyas4-Dec-09 23:47
bhavnvyas4-Dec-09 23:47 
AnswerRe: Querystring issue Pin
sashidhar4-Dec-09 23:55
sashidhar4-Dec-09 23:55 
GeneralRe: Querystring issue Pin
bhavnvyas4-Dec-09 23:59
bhavnvyas4-Dec-09 23:59 
GeneralRe: Querystring issue Pin
sashidhar5-Dec-09 0:04
sashidhar5-Dec-09 0:04 
GeneralRe: Querystring issue Pin
bhavnvyas5-Dec-09 0:11
bhavnvyas5-Dec-09 0:11 
AnswerRe: Querystring issue Pin
Abhishek Sur5-Dec-09 9:43
professionalAbhishek Sur5-Dec-09 9:43 
QuestionImage resize in asp.net Pin
Any_India4-Dec-09 22:34
Any_India4-Dec-09 22:34 
AnswerRe: Image resize in asp.net Pin
keyur satyadev4-Dec-09 22:50
keyur satyadev4-Dec-09 22:50 
public static string Resize(string InputFilePath, string Name, int TargetWidth, int TargetHeight, string Extension, string TargetFolder)
            {
                  string thumbnailFilePath = string.Empty;
                  string FileName = string.Empty;
                  Size newSize;
                  try
                  {
                        using (Bitmap bmp = new Bitmap(InputFilePath))
                        {
                              newSize = GetRelativeImageSize(bmp.Width, bmp.Height, TargetWidth, TargetHeight);
                              FileName = Name + Extension;
                              thumbnailFilePath = TargetFolder + FileName;
                              using (Bitmap thumb = new Bitmap((System.Drawing.Image)bmp, newSize))
                              {
                                    using (Graphics g = Graphics.FromImage(thumb)) // Create Graphics object from original Image
                                    {
                                          g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                                          g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
                                          g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                                          //Set Image codec of JPEG type, the index of JPEG codec is "1"
                                          System.Drawing.Imaging.ImageCodecInfo codec = GetImageCodec(Extension);
                                          //Set the parameters for defining the quality of the thumbnail... here it is set to 100%
                                          System.Drawing.Imaging.EncoderParameters eParams = new System.Drawing.Imaging.EncoderParameters(1);
                                          eParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
                                          //Now draw the image on the instance of thumbnail Bitmap object
                                          g.DrawImage(bmp, new Rectangle(0, 0, thumb.Width, thumb.Height));
                                          thumb.Save(thumbnailFilePath, codec, eParams);
                                    }
                              }
                        }
                  }
                  catch (Exception ex)
                  {
                        throw ex;
                  }
                  return FileName;
            }

//it will return the file name with resize.
private static Size GetRelativeImageSize(int SourceWidth, int SourceHeight, int TargetWidth, int TargetHeight)
{
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
if (SourceWidth <= TargetWidth && SourceHeight <= TargetHeight)
{
return new Size(SourceWidth, SourceHeight);
}
else if (TargetWidth == 0)
{
if (SourceHeight > TargetHeight)
{
nPercentH = ((float)TargetHeight / (float)SourceHeight);
nPercent = nPercentH;
}
else
return new Size(SourceWidth, SourceHeight);

}
else if (TargetHeight == 0)
{
if (SourceWidth > TargetWidth)
{
nPercentW = ((float)TargetWidth / (float)SourceWidth);
nPercent = nPercentW;
}
else
return new Size(SourceWidth, SourceHeight);

}
else
{
nPercentW = ((float)TargetWidth / (float)SourceWidth);
nPercentH = ((float)TargetHeight / (float)SourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
}
else
{
nPercent = nPercentW;
}
}
return new Size(Convert.ToInt32(SourceWidth * nPercent), Convert.ToInt32(SourceHeight * nPercent));
}

Regards
Keyur Satyadev

GeneralRe: Image resize in asp.net Pin
Any_India4-Dec-09 23:40
Any_India4-Dec-09 23:40 
GeneralRe: Image resize in asp.net Pin
keyur satyadev4-Dec-09 23:56
keyur satyadev4-Dec-09 23:56 
GeneralRe: Image resize in asp.net Pin
macielaf14-Aug-13 9:56
macielaf14-Aug-13 9:56 
AnswerRe: Image resize in asp.net Pin
sashidhar4-Dec-09 23:50
sashidhar4-Dec-09 23:50 
GeneralRe: Image resize in asp.net Pin
macielaf15-Aug-13 5:32
macielaf15-Aug-13 5:32 
Questionhelp me Pin
vbmadhavi4-Dec-09 21:38
vbmadhavi4-Dec-09 21:38 
AnswerRe: help me Pin
keyur satyadev4-Dec-09 21:48
keyur satyadev4-Dec-09 21:48 
AnswerRe: help me Pin
sashidhar4-Dec-09 22:04
sashidhar4-Dec-09 22:04 
AnswerRe: help me Pin
<<Tash18>>4-Dec-09 22:32
<<Tash18>>4-Dec-09 22:32 
QuestionASP.NET MCV Pin
mpavas4-Dec-09 21:17
mpavas4-Dec-09 21:17 
QuestionAspDotNetStoreFront Skinning Pin
22084-Dec-09 17:10
22084-Dec-09 17:10 
AnswerRe: AspDotNetStoreFront Skinning Pin
Adam Maras4-Dec-09 17:45
Adam Maras4-Dec-09 17:45 
GeneralRe: AspDotNetStoreFront Skinning Pin
22084-Dec-09 20:05
22084-Dec-09 20:05 
QuestionPrevious Page Pin
Munteanu Ciprian4-Dec-09 9:14
Munteanu Ciprian4-Dec-09 9:14 
AnswerRe: Previous Page Pin
Abhishek Sur4-Dec-09 11:55
professionalAbhishek Sur4-Dec-09 11:55 
QuestionAJAX control Toolkit Accordion Control problem Pin
Faisal Khatri4-Dec-09 5:18
Faisal Khatri4-Dec-09 5:18 
AnswerRe: AJAX control Toolkit Accordion Control problem Pin
keyur satyadev4-Dec-09 21:36
keyur satyadev4-Dec-09 21:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.