I have been assigned to create a web gallery that users can upload to.
Basically. it goes like this
upload image
map paths store on database.
create thumbnail sized image
link thumnmail to larger image.
The issue I am having is that for some reason I am not able to get thumbnail to be uploaded.
so the normal sized images upload just find as does the path.
the thumbnail path uploads fine. but the thumbnail image does not.
I am sure it is just something I have over looked and need a 2nd pair of eyes to see.
here is my code.
=============================
Protected
Sub bt__Upload_Click(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles bt_UpLoad.Click
' first, check whether a valid full-sized image was uploaded
If FullSizedImage.PostedFile
Is Nothing
Then
'Message.Text = "The full-sized image file does not exist."
Else ' full sized image was uploaded
' just working on the filenames
Dim FilenameAndExtension
As String = System.IO.Path.GetFileName(FullSizedImage.PostedFile.FileName)
Dim IndexOfDot
As Integer = FilenameAndExtension.LastIndexOf(".")
Dim FilenameOnly
As String = FilenameAndExtension.Substring(0, IndexOfDot)
Dim ExtensionOnly
As String = FilenameAndExtension.Substring(IndexOfDot + 1, FilenameAndExtension.Length - IndexOfDot - 1)
Dim ThumbnailFilename
As String = FilenameOnly &
"-t." & ExtensionOnly
' let's save the main image
Dim LocationToSave = Server.MapPath("~/Images/Portfolio/Full/")
Dim Full As
String = "http://exiled-studios.com/images/Portfolio/Full/" & FullSizedImage.FileName &
""
' to start, we'll load up full-sized image as an Image file
' (previously, it was just any old file ... could have been a Word document for all we know)
Dim FullSizePhoto
As System.Drawing.Image
' now that we have it as an image file, we can create a thumbnail easily
' first, we need to be prepared for a problem
Dim dummyCallBack
As System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack =
New System.Drawing.Image.GetThumbnailImageAbort(AddressOf CallBack)
' have gotten ready for a problem, let's create the thumbnail
Dim ThumbnailPhoto
As System.Drawing.Image
Dim Thumb As
String = "http://exiled-studios.com/images/Portfolio/Thumb/" & ThumbnailFilename &
""
' success!
'upload file paaths to database
Dim strConn
As String =
"Server=Server; Database=database; User ID=Username; Password=Password; Integrated Security=False"
Dim MySQL As
String = "Insert into tbl_Gallery(FullPath, ThumbPath, PostedBy, DateSubmitted) " & _
"Values (@FullPath, @ThumbPath, @PostedBy, @DateSubmitted)"
Dim MyConn
As New Data.SqlClient.SqlConnection(strConn)
Dim Cmd As
New Data.SqlClient.SqlCommand(MySQL, MyConn)
With Cmd.Parameters
.Add(
New Data.SqlClient.SqlParameter("@FullPath", Full))
.Add(
New Data.SqlClient.SqlParameter("@ThumbPath", Thumb))
.Add(
New Data.SqlClient.SqlParameter("@PostedBy", User.Identity.Name))
.Add(
New Data.SqlClient.SqlParameter("@DateSubmitted",
Date.Now))
End With
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
MyConn.Dispose()
'Message.Text = "The photo and its thumbnail has been saved."
End If
' was full sized image uploaded?
End Sub
If contentLength <> 0 Then
Dim fileName As String = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\") + 1)
Dim filePath As String = Server.MapPath("~/upload/PhotoAlbum/Products/" & Product_ID & "/Large/" & ObjImage.GetImageId & ".jpg")
Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(File1.PostedFile.InputStream)
Dim Result_image As Long = ObjImage.AddImage(Txt_ImageName.Text, Request.QueryString("Product_ID"))
File1.PostedFile.SaveAs(filePath)
Dim bitmap_Large As Bitmap = New Bitmap(image)
Dim bitmap_Thumb As Bitmap = New Bitmap(image, 118, 118)
Dim GraphicsWriter As Graphics = Graphics.FromImage(bitmap_Large)
Dim stringFormat As New StringFormat
stringFormat.FormatFlags = StringFormatFlags.DirectionVertical
GraphicsWriter.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
GraphicsWriter.FillRectangle(Brushes.Green, 0, 0, 25, bitmap_Large.Height)
GraphicsWriter.DrawString("Copyright " & DateTime.Now.Year, New Font("Verdana", 12, FontStyle.Bold), Brushes.White, New PointF(0, (bitmap_Large.Height / 2) - 122), stringFormat)
bitmap_Large.Save(MapPath("~/upload/PhotoAlbum/Products/" & Product_ID & "/Large/" & ObjImage.GetImageId & ".jpg"), image.RawFormat)
bitmap_Thumb.Save(MapPath("~/upload/PhotoAlbum/Products/" & Product_ID & "/thumb/" & ObjImage.GetImageId & ".jpg"), image.RawFormat)
BindData(Request.QueryString("Product_ID"))
End If
cheers
Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
http://www.aghausman.net
I think that you are saving the images in folder...........
Images/Portfolio/Full.....
where as you are saving different path into the Database i.e
images/Portfolio/Thumb
I think that you are saving the images in folder...........
Images/Portfolio/Full.....
where as you are saving different path into the Database i.e
images/Portfolio/Thumb
I think that this might be the problem.....
Thats what I was thinking and
I believe that peice of code is the culprit
" Dim LocationToSave = Server.MapPath("~/Images/Portfolio/Full/") "
What I am unsure of is how to modify or add to that to save to both places. thumb and full. [:S]
Dim bitmap_Thumb As Bitmap = New Bitmap(image, 118, 118)
bitmap_Thumb.Save(MapPath("~/Images/Portfolio/Thumb/"), image.RawFormat)
cheers
Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
http://www.aghausman.net
atrum
Member
42 Points
43 Posts
Thumb nail problem.
Mar 08, 2007 02:21 AM|LINK
Hello all,
I have been assigned to create a web gallery that users can upload to.
Basically. it goes like this
upload image
map paths store on database.
create thumbnail sized image
link thumnmail to larger image.
The issue I am having is that for some reason I am not able to get thumbnail to be uploaded.
so the normal sized images upload just find as does the path.
the thumbnail path uploads fine. but the thumbnail image does not.
I am sure it is just something I have over looked and need a 2nd pair of eyes to see.
here is my code.
=============================
Protected
Sub bt__Upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bt_UpLoad.Click ' first, check whether a valid full-sized image was uploaded If FullSizedImage.PostedFile Is Nothing Then 'Message.Text = "The full-sized image file does not exist." Else ' full sized image was uploaded
' just working on the filenames Dim FilenameAndExtension As String = System.IO.Path.GetFileName(FullSizedImage.PostedFile.FileName) Dim IndexOfDot As Integer = FilenameAndExtension.LastIndexOf(".") Dim FilenameOnly As String = FilenameAndExtension.Substring(0, IndexOfDot) Dim ExtensionOnly As String = FilenameAndExtension.Substring(IndexOfDot + 1, FilenameAndExtension.Length - IndexOfDot - 1) Dim ThumbnailFilename As String = FilenameOnly & "-t." & ExtensionOnly ' let's save the main image Dim LocationToSave = Server.MapPath("~/Images/Portfolio/Full/")FullSizedImage.PostedFile.SaveAs(LocationToSave + FilenameAndExtension)
Dim Full As String = "http://exiled-studios.com/images/Portfolio/Full/" & FullSizedImage.FileName & "" ' to start, we'll load up full-sized image as an Image file ' (previously, it was just any old file ... could have been a Word document for all we know) Dim FullSizePhoto As System.Drawing.ImageFullSizePhoto = System.Drawing.Image.FromFile(LocationToSave + FilenameAndExtension)
' now that we have it as an image file, we can create a thumbnail easily ' first, we need to be prepared for a problem Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbortdummyCallBack =
New System.Drawing.Image.GetThumbnailImageAbort(AddressOf CallBack) ' have gotten ready for a problem, let's create the thumbnail Dim ThumbnailPhoto As System.Drawing.ImageThumbnailPhoto = FullSizePhoto.GetThumbnailImage(200, 200, dummyCallBack, IntPtr.Zero)
' release our hold on the full-sized imageFullSizePhoto.Dispose()
' save the thumbnailThumbnailPhoto.Save(LocationToSave + ThumbnailFilename, ImageFormat.Jpeg)
Dim Thumb As String = "http://exiled-studios.com/images/Portfolio/Thumb/" & ThumbnailFilename & "" ' success! 'upload file paaths to database Dim strConn As String = "Server=Server; Database=database; User ID=Username; Password=Password; Integrated Security=False" Dim MySQL As String = "Insert into tbl_Gallery(FullPath, ThumbPath, PostedBy, DateSubmitted) " & _ "Values (@FullPath, @ThumbPath, @PostedBy, @DateSubmitted)" Dim MyConn As New Data.SqlClient.SqlConnection(strConn) Dim Cmd As New Data.SqlClient.SqlCommand(MySQL, MyConn) With Cmd.Parameters.Add(
New Data.SqlClient.SqlParameter("@FullPath", Full)).Add(
New Data.SqlClient.SqlParameter("@ThumbPath", Thumb)).Add(
New Data.SqlClient.SqlParameter("@PostedBy", User.Identity.Name)).Add(
New Data.SqlClient.SqlParameter("@DateSubmitted", Date.Now)) End WithMyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
MyConn.Dispose()
'Message.Text = "The photo and its thumbnail has been saved." End If ' was full sized image uploaded? End Sub
Public Function CallBack() As Boolean
Return False End Function============================================
aghausman12
Contributor
3035 Points
550 Posts
Re: Thumb nail problem.
Mar 08, 2007 05:35 AM|LINK
try it out
If contentLength <> 0 Then Dim fileName As String = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\") + 1) Dim filePath As String = Server.MapPath("~/upload/PhotoAlbum/Products/" & Product_ID & "/Large/" & ObjImage.GetImageId & ".jpg") Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(File1.PostedFile.InputStream) Dim Result_image As Long = ObjImage.AddImage(Txt_ImageName.Text, Request.QueryString("Product_ID")) File1.PostedFile.SaveAs(filePath) Dim bitmap_Large As Bitmap = New Bitmap(image) Dim bitmap_Thumb As Bitmap = New Bitmap(image, 118, 118) Dim GraphicsWriter As Graphics = Graphics.FromImage(bitmap_Large) Dim stringFormat As New StringFormat stringFormat.FormatFlags = StringFormatFlags.DirectionVertical GraphicsWriter.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias GraphicsWriter.FillRectangle(Brushes.Green, 0, 0, 25, bitmap_Large.Height) GraphicsWriter.DrawString("Copyright " & DateTime.Now.Year, New Font("Verdana", 12, FontStyle.Bold), Brushes.White, New PointF(0, (bitmap_Large.Height / 2) - 122), stringFormat) bitmap_Large.Save(MapPath("~/upload/PhotoAlbum/Products/" & Product_ID & "/Large/" & ObjImage.GetImageId & ".jpg"), image.RawFormat) bitmap_Thumb.Save(MapPath("~/upload/PhotoAlbum/Products/" & Product_ID & "/thumb/" & ObjImage.GetImageId & ".jpg"), image.RawFormat) BindData(Request.QueryString("Product_ID")) End Ifcheers
http://www.aghausman.net
atrum
Member
42 Points
43 Posts
Re: Thumb nail problem.
Mar 08, 2007 05:44 AM|LINK
Hmm ok thanks. Ill give that a try.
Dhaliwal
Participant
992 Points
231 Posts
Re: Thumb nail problem.
Mar 08, 2007 05:46 AM|LINK
where as you are saving different path into the Database i.e images/Portfolio/Thumb
I think that this might be the problem.....
atrum
Member
42 Points
43 Posts
Re: Thumb nail problem.
Mar 08, 2007 06:01 AM|LINK
Thats what I was thinking and
I believe that peice of code is the culprit
" Dim LocationToSave = Server.MapPath("~/Images/Portfolio/Full/") "
What I am unsure of is how to modify or add to that to save to both places. thumb and full. [:S]
aghausman12
Contributor
3035 Points
550 Posts
Re: Thumb nail problem.
Mar 08, 2007 06:07 AM|LINK
Dim bitmap_Thumb As Bitmap = New Bitmap(image, 118, 118) bitmap_Thumb.Save(MapPath("~/Images/Portfolio/Thumb/"), image.RawFormat)cheershttp://www.aghausman.net
atrum
Member
42 Points
43 Posts
Re: Thumb nail problem.
Mar 08, 2007 06:13 AM|LINK
Ok. I was 1/3 right
here is what I think the rest of my problem is and if any one could help me out here on this.
So here is where the upload is supposed to be sending the full image.
Dim LocationToSave = Server.MapPath("~/Images/Portfolio/Full/")
I just noticed that my thumb nail code is also using that same LocationToSave Variable so both images are being sent to the same place.
Dim
ThumbnailPhoto As System.Drawing.ImageThumbnailPhoto.Save(LocationToSave + ThumbnailFilename, ImageFormat.Jpeg)
.......
What do I need to add to sepurate the paths into full and thumb like I need.
I checked my database and the paths are being saved correctly but the thumb is not going to the same directory.
Dhaliwal
Participant
992 Points
231 Posts
Re: Thumb nail problem.
Mar 08, 2007 06:24 AM|LINK
Dim LocationToSaveFull = Server.MapPath("~/Images/Portfolio/Full/")
FullSizedImage.PostedFile.SaveAs(LocationToSaveFull + FilenameAndExtension)
// while saving ThumbNailDim LocationToSaveThumb = Server.MapPath("~/Images/Portfolio/Thumb/")
ThumbnailPhoto.Save(LocationToSaveThumb + ThumbnailFilename, ImageFormat.Jpeg)
atrum
Member
42 Points
43 Posts
Re: Thumb nail problem.
Mar 08, 2007 06:24 AM|LINK
Thank you didn't see this post untill I Got done with my last. one. testing now.
Ok the code you gave didn't work. but!! :D it gave me the clue I needed to get it working. basically.
I did this
"'Dim LocationToSaveThumb = Server.MapPath("~/Images/Portfolio/Thumb/")
Dim ThumbnailPhoto As System.Drawing.Image
ThumbnailPhoto = FullSizePhoto.GetThumbnailImage(200, 200, dummyCallBack, IntPtr.Zero""
It works perfectly now. Thank you very very much !!!!
Dhaliwal
Participant
992 Points
231 Posts
Re: Thumb nail problem.
Mar 08, 2007 06:24 AM|LINK
Dim LocationToSaveFull = Server.MapPath("~/Images/Portfolio/Full/")
FullSizedImage.PostedFile.SaveAs(LocationToSaveFull + FilenameAndExtension)
// while saving ThumbNailDim LocationToSaveThumb = Server.MapPath("~/Images/Portfolio/Thumb/")
ThumbnailPhoto.Save(LocationToSaveThumb + ThumbnailFilename, ImageFormat.Jpeg)