第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在asp.net中調(diào)整圖像大小而不丟失圖像質(zhì)量

在asp.net中調(diào)整圖像大小而不丟失圖像質(zhì)量

弒天下 2019-12-26 14:21:26
我正在開發(fā)一個ASP.NET 3.5 Web應用程序,該應用程序允許我的用戶上傳jpeg,gif,bmp或png圖像。如果上載的圖像尺寸大于103 x 32,則我希望將上載的圖像尺寸調(diào)整為103 x32。我已經(jīng)閱讀了一些博客文章和文章,還嘗試了一些代碼示例,但似乎沒有任何用處。有沒有人成功做到這一點?
查看完整描述

3 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經(jīng)驗 獲得超3個贊

不久前,我遇到了同樣的問題,并以這種方式處理:


private Image RezizeImage(Image img, int maxWidth, int maxHeight)

{

    if(img.Height < maxHeight && img.Width < maxWidth) return img;

    using (img)

    {

        Double xRatio = (double)img.Width / maxWidth;

        Double yRatio = (double)img.Height / maxHeight;

        Double ratio = Math.Max(xRatio, yRatio);

        int nnx = (int)Math.Floor(img.Width / ratio);

        int nny = (int)Math.Floor(img.Height / ratio);

        Bitmap cpy = new Bitmap(nnx, nny, PixelFormat.Format32bppArgb);

        using (Graphics gr = Graphics.FromImage(cpy))

        {

            gr.Clear(Color.Transparent);


            // This is said to give best quality when resizing images

            gr.InterpolationMode = InterpolationMode.HighQualityBicubic;


            gr.DrawImage(img,

                new Rectangle(0, 0, nnx, nny),

                new Rectangle(0, 0, img.Width, img.Height),

                GraphicsUnit.Pixel);

        }

        return cpy;

    }


}


private MemoryStream BytearrayToStream(byte[] arr)

{

    return new MemoryStream(arr, 0, arr.Length);

}


private void HandleImageUpload(byte[] binaryImage)

{

    Image img = RezizeImage(Image.FromStream(BytearrayToStream(binaryImage)), 103, 32);

    img.Save("IMAGELOCATION.png", System.Drawing.Imaging.ImageFormat.Gif);

}

我剛剛讀到,這是獲得最高質(zhì)量的方法。


查看完整回答
反對 回復 2019-12-26
  • 3 回答
  • 0 關(guān)注
  • 735 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號