The following warnings occurred:
Warning [2] Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\scripts.php:2) - Line: 1701 - File: D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions.php PHP 5.2.17 (WINNT)
File Line Function
[PHP]   errorHandler->error
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions.php 1701 header
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions.php 1763 my_setcookie
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions_indicators.php 42 my_set_array_cookie
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\showthread.php 578 mark_thread_read
Warning [2] Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\scripts.php:2) - Line: 1701 - File: D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions.php PHP 5.2.17 (WINNT)
File Line Function
[PHP]   errorHandler->error
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions.php 1701 header
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions.php 1763 my_setcookie
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions_indicators.php 218 my_set_array_cookie
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\inc\functions_indicators.php 48 mark_forum_read
D:\inetpub\vhosts\visionwebdirectory.com\httpdocs\forum\showthread.php 578 mark_thread_read





Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# code to resize image
06-30-2013, 06:31 PM
Post: #1
C# code to resize image
using System.Data;

using System.Drawing;

using System.Windows.Forms;

using System.IO;

using System.Drawing.Imaging;

private void saveFile()

{

int width = Convert.ToInt32(txtWidth.Text.Trim());

int height = Convert.ToInt32(txtHeight.Text.Trim());

string strImage = txtPath.Text ;

Int32 i = strImage.LastIndexOf('/');

string strSub = strImage.Substring(i + 1);

Int32 TotalLength = strSub.Length;

Int32 FileLength = strSub.LastIndexOf('.');

string strExtension = strSub.Substring(FileLength + 1, TotalLength - (FileLength + 1));

string strFileName = strSub.Substring(0, FileLength);

strExtension = strExtension.ToLower();

if (strExtension == "jpg" || strExtension == "gif" || strExtension == "jpeg" || strExtension == "bmp" || strExtension == "png")

{

string strAddress = "C://Images/";

string strPathImage = DateTime.Now.Year.ToString() + "" + DateTime.Now.Month.ToString() + "" + DateTime.Now.Day.ToString() + "" + DateTime.Now.Hour.ToString() + "" + DateTime.Now.Minute.ToString() + "" + DateTime.Now.Second.ToString() + "Image." + strExtension;

Bitmap bmp = CreateThumbnail(strImage,width, height);

bmp.Save(strAddress + "/" + strPathImage);

}

}

public static Bitmap CreateThumbnail(string upFile, int width, int height)

{

Image img = Image.FromFile(upFile);

Bitmap postedFile = new Bitmap(img);

System.Drawing.Bitmap bmpOut;

ImageFormat Format = postedFile.RawFormat;

decimal Ratio;

int NewWidth;

int NewHeight;

if (postedFile.Width < width && postedFile.Height < height)

{

return postedFile;

}

if ((postedFile.Width postedFile.Height))

{

Ratio = Convert.ToDecimal(Convert.ToDecimal(width) / Convert.ToDecimal(postedFile.Width));

NewWidth = width;

decimal Temp = postedFile.Height * Ratio;

NewHeight = Convert.ToInt32(Temp);

}

else

{

Ratio = Convert.ToDecimal(Convert.ToDecimal(height) / Convert.ToDecimal(postedFile.Height));

NewHeight = height;

decimal Temp = postedFile.Width * Ratio;

NewWidth = Convert.ToInt32(Temp);

}

bmpOut = new Bitmap(NewWidth, NewHeight);

Graphics g = Graphics.FromImage(bmpOut);

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

g.FillRectangle(Brushes.White, 0, 0, NewWidth, NewHeight);

g.DrawImage(postedFile, 0, 0, NewWidth, NewHeight);

postedFile.Dispose();

return bmpOut;

}
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)