PDA

View Full Version : نحوه ایجاد thumb



shokoohhakemi
شنبه 05 آذر 1390, 13:00 عصر
سلام

لطفا در رابطه با ایجاد تامب برای عکس های آپلود شده توضیحاتی بدهید ...



با تشکر

smm2006sh
شنبه 05 آذر 1390, 16:12 عصر
سلام
یه سرچی بزن زود تر جواب میگیری
http://barnamenevis.org/showthread.php?295775-%D8%A7%DB%8C%D8%AC%D8%A7%D8%AF-%DA%AF%D8%A7%D9%84%D8%B1%DB%8C-%D8%B9%DA%A9%D8%B3-%D8%AF%D8%A7%DB%8C%D9%86%D8%A7%D9%85%DB%8C%DA%A9-%D8%AA%D9%88%D8%B3%D8%B7-Jquery&highlight=%D9%86%D8%AD%D9%88%D9%87+%D8%A7%DB%8C%D8 %AC%D8%A7%D8%AF+thumb

jaykob
یک شنبه 06 آذر 1390, 15:26 عصر
سلام

می تونید از تابع زیر استفاده کنید . هر خط هم توضیحات خودش رو داره :



private void ThumbCreate()
{
//////////////////////////////// spmall pic /////////////////////////////////////////

if (FileUpload1.HasFile)
{
// Find the fileUpload control
string filename = FileUpload1.FileName;

// Check if the directory we want the image uploaded to actually exists or not
if (!Directory.Exists(MapPath(@"images\gallrey\thumb")))
{
// If it doesn't then we just create it before going any further
Directory.CreateDirectory(MapPath(@"images\gallrey\thumb"));
}
// Specify the upload directory
string directory = Server.MapPath(@"images\gallrey\thumb\");

// Create a bitmap of the content of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(FileUpload1.FileContent);

// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth / origHeight;
int newWidth = 210;
int newHeight = 100;

// Create a new bitmap which will hold the previous resized bitmap
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
// Create a graphic based on the new bitmap
Graphics oGraphics = Graphics.FromImage(newBMP);
// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
// Save the new graphic file to the server
newBMP.Save(directory + filename);

// Once finished with the bitmap objects, we deallocate them.
originalBMP.Dispose();
newBMP.Dispose();
oGraphics.Dispose();

// Write a message to inform the user all is OK

}
else
{
lblResult.Text = "فایل کوچک ساخته نشد";
}
///////////////////////////////////////////////////// small pic /////////////////////////////////////////////////
}