استفاده از Thumbnail برای تصاویر در گریدویو
سلام
من یک سری تصویر دارم که اونها در یک فولدر ذخیره کردهام و نام اون تصاویر را در دیتابیس ذخیره کردهام و برای بازیابی اونها در گرید ویو به صورت زیر عمل میکنم(که نام تصاویر با فیلد namepicture مشخص میشود ودر پوشه images ذخیره شده)
کد:
کد:
<asp:GridViewID="GridView2"runat="server"AutoGenerateColumns="False"DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<tdstyle="vertical-align: middle; width: 130px; height: 130px; text-align: center">
<imgsrc=".\Images\<%#Eval("namepicture")%>"></td>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
من میخواهم وقتی تصاویر را اپلود میکنم پهنا و ارتفاع انها را نیز مشخص کنم و بر اساس این اندازه ها تصاویر را در گرید ویو نمایش دهم.
من خودم از کد زیر برای تغییر سایز عکس در خارج از گریدویو استفاده کردهام
کد:
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs)
' get the file name -- fall800.jpg
Dim file AsString = Request.QueryString("file")
' create an image object, using the filename we just retrieved
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(file))
' create the actual thumbnail image
Dim thumbnailImage As System.Drawing.Image = image.GetThumbnailImage(100, 64, New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback), IntPtr.Zero)
' make a memory stream to work with the image bytes
Dim imageStream As MemoryStream = New MemoryStream()
' put the image into the memory stream
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg)
' make byte array the same size as the image
Dim imageContent() AsByte = NewByte(imageStream.Length) {}
' rewind the memory stream
imageStream.Position = 0
' load the byte array with the image
imageStream.Read(imageContent, 0, CType(imageStream.Length, Integer))
' return byte array to caller with image type
Response.ContentType = "image/jpeg"
Response.BinaryWrite(imageContent)
EndSub
PublicFunction ThumbnailCallback() AsBoolean
ReturnTrue
EndFunction
ودر صفحه نمایش تصاویر:
کد
کد:
<asp:Imageid="Image1"runat="server"ImageUrl="MakeThumbnail1.aspx?file=piic.jpg"/>
حالا سوال من اینه برای تصاویر در گرید ویو چگونه باید این کد تغییر سایز را استفاده کنم؟