2008年11月10日 星期一

如何產生圖片縮圖

Bitmap bm= (Bitmap)Bitmap.FromFile(FileName);
int shtWidth, shtHeight;
if (bm.Width>bm.Height)
{
shtWidth = 250;//max width
shtHeight=bm.Height*shtWidth/bm.Width;
}
else
{
shtHeight = 250;//max height
shtWidth = bm.Width*shtHeight/bm.Height;
}
Bitmap resized = new Bitmap(shtWidth, shtHeight);
Graphics g = Graphics.FromImage(resized);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bm, new Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel);
g.Dispose();
bm.Dispose();
resized.Save(SCANPREVIEWFILE, ImageFormat.Jpeg);

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...