[英]cropping a image
我有一個要求裁剪圖像並將其保存在數據庫中的要求。 當用戶上傳他/她的照片時,首先將原始圖像制成大尺寸圖像。 然后將大圖像裁剪並保存為拇指圖像。 因此,共有3種尺寸:原始尺寸,大尺寸(需要由用戶裁剪),縮略圖圖像。
因此,我在Internet上找到了進行此裁剪的控件。 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;
}
}
生成大圖像后,需要對其進行裁剪。 這是我用來裁剪圖像的代碼/ dll
<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(“ images / cropped.jpg”))將images / cropped.jpg作為其參數。 我應該如何更改代碼,使其采用大圖像而不是“ images / cropped.jpg”,我的意思是這樣的:wci1.Crop(Server.MapPath(largeimage)。
提前謝謝你孫
將大版本保存到磁盤,然后在方法中進行引用。
然后,您可以使用
File.IO.Delete
之后將其刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.