PDA

View Full Version : مشکل در ایجاد Thumbnail



my_blithe
دوشنبه 06 اسفند 1386, 19:12 عصر
سلام
من برای کوچک ننمایی تصاویر از این کدها استفاده میکنم ولی در پایان تصویر با همون حجم اولیه روی صفحه لود میشه مشکل چیه ؟؟

برای قسمت loadpage در صفحه ShowThumbnail.aspx از این کد :


'Read in the image filename to create a thumbnail of

Dim imageUrl As String = Request.QueryString("img"(

'Read in the width and height
Dim imageHeight As Integer = Request.QueryString("h")
Dim imageWidth As Integer = Request.QueryString("w")

'Make sure that the image URL doesn't contain any /'s or \'s
If imageUrl.IndexOf("/") >= 0 Or imageUrl.IndexOf("\") >= 0 Then
'We found a / or \
Response.End()
End If

'Add on the appropriate directory
imageUrl = "mypics/" & imageUrl

Dim fullSizeImg As System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(image Url))

'Do we need to create a thumbnail?
Response.ContentType = "image/jpg"

If imageHeight > 0 And imageWidth > 0 Then
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack = New System.Drawing.Image.GetThumbnailImageAbort(Addres sOf ThumbnailCallback)

Dim thumbNailImg As System.Drawing.Image


thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero)


fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
End If





و در صفحه آلبومم از این کدها


Public Function img_resize(ByVal picname As String,ByVal maxHeight As Integer, ByVal maxWidth As Integer) As String

Dim currentImage As System.Drawing.Image = System.Drawing.Image.FromFile(server.mappath("mypics\") + picname)

Dim imgHeight, imgWidth As Integer
imgHeight = currentImage.Height
imgWidth = currentImage.Width

If imgWidth > maxWidth Or imgHeight > maxHeight Then
'Determine what dimension is off by more
Dim deltaWidth As Integer = imgWidth - maxWidth
Dim deltaHeight As Integer = imgHeight - maxHeight
Dim scaleFactor As Double

If deltaHeight > deltaWidth Then
'Scale by the height
scaleFactor = maxHeight / imgHeight
Else
'Scale by the Width
scaleFactor = maxWidth / imgWidth
End If

imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If


Dim html As String

If imgHeight <> currentImage.Height Or imgWidth <> currentImage.Width Then
html = "<a href=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """>" & _
"<img src=""ShowThumbnail.aspx?img=" & Path.GetFileName(s) & "&w=" & _
imgWidth & "&h=" & imgHeight & """ " & _
"height=""" & imgHeight & """ width=""" & imgWidth & """ border=1>" & _
"</a>"
Else

html = "<a href=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """>" & _
"<img src=""ShowThumbnail.aspx?img=" & Path.GetFileName(s) & """ " & _
"height=""" & imgHeight & """ width=""" & imgWidth & """ border=1>" & _
"</a>"

End If
Return html



End Function


و در خود صفحه از این کد برای یک گریدویو






<asp:GridView ID="GridView3" runat="server" AllowPaging="True" AllowSorting="True"AutoGenerateColumns="False" DataKeyNames="reply_pk" DataSourceID="reply_source"Width="100%" GridLines="None">
<Columns>
<asp:TemplateFieldSortExpression="reply_user">

<ItemTemplate>
<%#img_resize(Eval("my_img"),100, 80)%>

</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



حالا مشکل از کجاست ؟؟؟؟؟

البته من متن کامل مقاله آموزشی این موضوع رو گذاشتم اگه کسی کمکم کنه ممنون میشم....

my_blithe
دوشنبه 06 اسفند 1386, 19:15 عصر
این فایل آموزشی که گفته بودم

کمک ................................

cpu0001100110000101
دوشنبه 06 اسفند 1386, 21:30 عصر
همونطور که قبلا کاملا توضیح دادم ...
http://barnamenevis.org/forum/showthread.php?t=92941
و البته مسلما حجم فایل حاصل کمتر خواهد بود

araz_pashazadeh
دوشنبه 20 اسفند 1386, 21:34 عصر
با عرض سلام و خسته نباشید خدمت دوستان.
من هم از کد بالا که دوستم نوشته بود استفاده کردم اما درست کار نکرد خودم تغییراتی رو به کد دادم و نتیجه هم داد اما قسمت اصلی که کم کردن سایز تصویر مورد نظر بود خیای تلاش کردم اما به نتیجهای نرسیدم.
البته من این کارو در #C انجام دادم ممنون می شم اگه راهنمائیم کنید؟؟؟؟

araz_pashazadeh
چهارشنبه 22 اسفند 1386, 21:42 عصر
من هم از کد بالا که دوستم نوشته بود استفاده کردم اما درست کار نکرد خودم تغییراتی رو به کد دادم و نتیجه هم داد اما قسمت اصلی که کم کردن سایز تصویر مورد نظر بود خیای تلاش کردم اما به نتیجهای نرسیدم.

کدی که برای قسمت کوچک کردن عکس نوشتم رو می زارم اگه مشکلی بود در خدمتم

string saveFile;
string savePath;
saveFile = Path.Combine(Request.PhysicalApplicationPath, "Images");
savePath = Path.Combine(saveFile, FileUpload1.FileName);
FileUpload1.SaveAs(savePath);
Image1.ImageUrl = Path.Combine("Images", FileUpload1.FileName);
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(@"Images\" + FileUpload1.FileName));
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(64, 64, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero);
thumbnailImage.Save(Server.MapPath(@"ReSizeImages\" + FileUpload1.FileName), System.Drawing.Imaging.ImageFormat.Jpeg);
//Image2.ImageUrl = Path.Combine(Request.PhysicalApplicationPath, @"ReSizeImages\" + FileUpload1.FileName);
Image2.ImageUrl = Path.Combine(@"ReSizeImages\", FileUpload1.FileName);

nazila_jon
شنبه 14 دی 1387, 22:47 عصر
بچه ها من این دستورات رو به vb تبدیل کردم

منتها به path ایراد میگیره

این path چیه؟؟





Dim saveFile As String
Dim savePath As String
saveFile = Path.Combine(Request.PhysicalApplicationPath, "Images")
savePath = Path.Combine(saveFile, FileUpload1.FileName)
FileUpload1.SaveAs(savePath)
Image1.ImageUrl = Path.Combine("Images", FileUpload1.FileName)
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("Images\" & FileUpload1.FileName))
Dim thumbnailImage As System.Drawing.Image = image.GetThumbnailImage(64, 64, New System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero)
thumbnailImage.Save(Server.MapPath("ReSizeImages\" & FileUpload1.FileName), System.Drawing.Imaging.ImageFormat.Jpeg)
'Image2.ImageUrl = Path.Combine(Request.PhysicalApplicationPath, @"ReSizeImages\" + FileUpload1.FileName);
Image2.ImageUrl = Path.Combine("ReSizeImages\", FileUpload1.FileName)