• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 6 رای - 3.17 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: تبدیل عکس به آیکون
حالت موضوعی
#1
کد:
private Icon MakeIcon(Image img, int size, bool keepAspectRatio)

        {

            Bitmap square = new Bitmap(size, size); // create new bitmap

            Graphics g = Graphics.FromImage(square); // allow drawing to it



            int x, y, w, h; // dimensions for new image



            if (!keepAspectRatio || img.Height == img.Width)

            {

                // just fill the square

                x = y = 0; // set x and y to 0

                w = h = size; // set width and height to size

            }

            else

            {

                // work out the aspect ratio

                float r = (float)img.Width / (float)img.Height;



                // set dimensions accordingly to fit inside size^2 square

                if (r > 1)

                { // w is bigger, so divide h by r

                    w = size;

                    h = (int)((float)size / r);

                    x = 0; y = (size - h) / 2; // center the image

                }

                else

                { // h is bigger, so multiply w by r

                    w = (int)((float)size * r);

                    h = size;

                    y = 0; x = (size - w) / 2; // center the image

                }

            }



            // make the image shrink nicely by using HighQualityBicubic mode

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

            g.DrawImage(img, x, y, w, h); // draw image with specified dimensions

            g.Flush(); // make sure all drawing operations complete before we get the icon



            // following line would work directly on any image, but then

            // it wouldn't look as nice.

            return Icon.FromHandle(square.GetHicon());

        }
+ نوشته شده در  جمعه یازدهم مرداد 1387ساعت 15:9  توسط گروه نرم افزاری قو  |  آرشیو نظرات
تغییر اندازه عکس
با استفاه از این کد شما می تونید یک عکس رو به اندازه یک دصد دلخواه تغییر اندازه بدین

public Image Resize(Image img, int percentage)

        {

            //get the height and width of the image

            int originalW = img.Width;

            int originalH = img.Height;



            //get the new size based on the percentage change

            int resizedW = (int)(originalW * percentage);

            int resizedH = (int)(originalH * percentage);



            //create a new Bitmap the size of the new image

            Bitmap bmp = new Bitmap(resizedW, resizedH);

            //create a new graphic from the Bitmap

            Graphics graphic = Graphics.FromImage((Image)bmp);

            graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;

            //draw the newly resized image

            graphic.DrawImage(img, 0, 0, resizedW, resizedH);

            //dispose and free up the resources

            graphic.Dispose();

            //return the image

            return (Image)bmp;

        }
 
پاسخ
  


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  سورس کد تبدیل عکس رنگی به سیاه سفید (سی شارپ) Amin_Mansouri 1 7,223 10-08-2022، 08:06 PM
آخرین ارسال: sonusood
  سورس کد تبدیل عکس به ایکون ( سی شارپ ) Amin_Mansouri 1 4,385 10-08-2022، 07:37 PM
آخرین ارسال: sonusood
  تبدیل عکس jpg به فرمت jpeg وبلعکس Sanazjoon 1 4,146 05-12-2014، 08:15 PM
آخرین ارسال: Amin_Mansouri
  سورس کد تبدیل متن به صدا (سی شارپ) Amin_Mansouri 7 15,010 12-18-2013، 12:51 PM
آخرین ارسال: sal
  تبدیل تاریخ شمسی به میلادی Ghoghnus 1 6,893 12-03-2012، 05:52 PM
آخرین ارسال: haman313
  مشکل در تبدیل تاریخ! Ghoghnus 4 6,329 05-27-2012، 10:49 AM
آخرین ارسال: Ghoghnus
  ابزاری برای تبدیل کد vb.net به C# و بالعکس Ghoghnus 0 5,034 10-31-2011، 03:25 PM
آخرین ارسال: Ghoghnus

پرش به انجمن:


Browsing: 1 مهمان