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);

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...