مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

reza74

عضویت از 1393/09/08

کراپ،کاهش سایز تصاویر سمت کاربر و سپس اپلود سمت سرور در asp.net mvc

  • چهارشنبه 22 فروردین 1397
  • 16:09
تشکر میکنم
راهنمایی میخواستم جهت کراپ،کاهش سایز تصاویر سمت کاربر و سپس اپلود سمت سرور در asp.net mvc

پاسخ های این پرسش

تعداد پاسخ ها : 9 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • چهارشنبه 22 فروردین 1397
  • 16:46

من از کلاس زیر استفاده میکنم

using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace ThemeShop.Utilities.Convertor
{
        public class ImageResizer
        {
        /// <summary>
        /// Resize image with a directory as source
        /// </summary>
        /// <param name="OriginalFileLocation">Image location</param>
        /// <param name="heigth">new height</param>
        /// <param name="width">new width</param>
        /// <param name="keepAspectRatio">keep the aspect ratio</param>
        /// <param name="getCenter">return the center bit of the image</param>
        /// <returns>image with new dimentions</returns>
        public void ResizeImageFromFile(string OriginalFileLocation, int heigth, int width, Boolean keepAspectRatio, Boolean getCenter)
        {
            int newheigth = heigth;
            System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFileLocation);

            // Prevent using images internal thumbnail
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (keepAspectRatio || getCenter)
            {
                int bmpY = 0;
                double resize = (double)FullsizeImage.Width / (double)width;//get the resize vector
                if (getCenter)
                {
                    bmpY = (int)((FullsizeImage.Height - (heigth * resize)) / 2);// gives the Y value of the part that will be cut off, to show only the part in the center
                    Rectangle section = new Rectangle(new Point(0, bmpY), new Size(FullsizeImage.Width, (int)(heigth * resize)));// create the section to cut of the original image
                                                                                                                                 //System.Console.WriteLine("the section that will be cut off: " + section.Size.ToString() + " the Y value is minimized by: " + bmpY);
                    Bitmap orImg = new Bitmap((Bitmap)FullsizeImage);//for the correct effect convert image to bitmap.
                    FullsizeImage.Dispose();//clear the original image
                    using (Bitmap tempImg = new Bitmap(section.Width, section.Height))
                    {
                        Graphics cutImg = Graphics.FromImage(tempImg);//              set the file to save the new image to.
                        cutImg.DrawImage(orImg, 0, 0, section, GraphicsUnit.Pixel);// cut the image and save it to tempImg
                        FullsizeImage = tempImg;//save the tempImg as FullsizeImage for resizing later
                        orImg.Dispose();
                        cutImg.Dispose();
                        FullsizeImage.GetThumbnailImage(width, heigth, null, IntPtr.Zero).Save(OriginalFileLocation,ImageFormat.Jpeg);
                    }
                }
                else newheigth = (int)(FullsizeImage.Height / resize);//  set the new heigth of the current image
            }//return the image resized to the given heigth and width
             FullsizeImage.GetThumbnailImage(width, newheigth, null, IntPtr.Zero).Save(OriginalFileLocation, ImageFormat.Jpeg);
        }
    }

    }

کاربر سایت

reza74

عضویت از 1393/09/08

  • چهارشنبه 22 فروردین 1397
  • 17:15
مهندس مدائنی امکانش هست یک پروژه نمونه پیوست فرماید،سپاس گزارم
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • چهارشنبه 22 فروردین 1397
  • 17:37

مسیر فایل رو بهمراه طول و عرض مورد نظر به این متد ارسال کنید

همین

کاربر سایت

reza74

عضویت از 1393/09/08

  • چهارشنبه 22 فروردین 1397
  • 19:31
مهندس قبل از اپلود این متد فراخوان شودیا پس از آپلود؟سوال دیگر داشتم نسبت به کراپ تصویر
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • پنجشنبه 23 فروردین 1397
  • 09:45

قبلش که نمیتونید

باید بعد از آپلود استفاده کنید

کاربر سایت

reza74

عضویت از 1393/09/08

  • پنجشنبه 23 فروردین 1397
  • 12:10
مهندس مجدد ممنونم،برای کراپ تصویر چه تکنیکی را توصیه میکنید؟
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • پنجشنبه 23 فروردین 1397
  • 12:21
کاربر سایت

reza74

عضویت از 1393/09/08

  • پنجشنبه 23 فروردین 1397
  • 14:41
سپاس،جهت ان تایم بود،مهندس
کاربر سایت

mohammadd

عضویت از 1395/12/08

  • یکشنبه 18 آذر 1397
  • 14:47

متاسفانه لینک فایل JS این آموزش دیگه در دسترس نیست

میشه اصلاح کنید یا کسی فایل JS رو داره بزاره

برش و آپلود تصویر با Thumbnail با استفاده از jQuery و HTML5 در MVC

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)