1
我有一個需要將圖像裁剪並保存在數據庫中。 當用戶上傳他/她的照片時,首先使用該原始圖像製作大尺寸圖像。 然後將大圖像裁剪並保存爲拇指圖像。 所以有3種尺寸:原始,大(需要由用戶剪裁),拇指圖像。裁剪圖像
所以我在互聯網上找到了一個控制這個剪裁。 http://webcropimage.codeplex.com/releases/view 這是用於使原廠
public static byte[] MakeThumb(byte[] fullsize, int maxwidth)
{
Image iOriginal, iThumb;
double scale;
iOriginal = Image.FromStream(new MemoryStream(fullsize));
if (iOriginal.Width > maxwidth)
{
scale = iOriginal.Width/maxwidth;
int newheight = Convert.ToInt32(iOriginal.Height/scale);
iThumb = new Bitmap(iOriginal, maxwidth, newheight);
MemoryStream m = new MemoryStream();
iThumb.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg);
return m.GetBuffer();
}
else
{
return fullsize;
}
}
一旦生成大的圖像,它需要被修剪的大的圖像的代碼。下面是我使用的裁剪圖像
<asp:Button ID="btnCrop" runat="server" Text="Crop" onclick="btnCrop_Click" />
<cs:CropImage ID="wci1" runat="server"
Image="Image1"
MinSize="100,100"
MaxSize="150,150"
W="150"
H="150"
/>
protected void btnCrop_Click(object sender, EventArgs e)
{
/* thats the method to crop and save the image.*/
wci1.Crop(Server.MapPath("images/cropped.jpg"));
/*
this part is just to show the image after its been cropped and saved! so focus on just the code above.
*/
Image img = new Image();
img.ImageUrl = "images/cropped.jpg?rnd=" + (new Random()).Next(); // added random for caching issue.
this.Controls.Add(img);
}
wci1.Crop(使用Server.Mappath( 「圖像/ cropped.jpg」))代碼/ DLL拍攝圖像/ cropped.jpg作爲它的參數。 我應該如何改變代碼,以便它需要一個大的圖像,而不是「圖像/ cropped.jpg」 我的意思是這樣:wci1.Crop(使用Server.Mappath(largeimage)
預先感謝您 孫
編寫一個包裝方法,並調用它來代替wci1.Crop'。並且在包裝方法中,你可以調用'wci1.Crop' – 2012-01-06 06:24:34
謝謝@RanhiruCooray – user575219 2012-01-08 17:53:57