Thumb nail problem.http://forums.asp.net/t/1084216.aspx/1?Thumb+nail+problem+Thu, 08 Mar 2007 06:24:51 -050010842161610477http://forums.asp.net/p/1084216/1610477.aspx/1?Thumb+nail+problem+Thumb nail problem. <p>Hello all,</p> <p>&nbsp;</p> <p>I have been assigned to create a web gallery that users can upload to. </p> <p>&nbsp;Basically. it goes like this</p> <p>upload image</p> <p>map paths store on database.</p> <p>create thumbnail sized image</p> <p>link thumnmail to larger image.</p> <p>The issue I am having is that for some reason I am not able to get thumbnail to be uploaded. </p> <p>so the normal sized images upload just find as does the path.</p> <p>the thumbnail path uploads fine. but the thumbnail image does not.</p> <p>&nbsp;</p> <p>I am sure it is just something I have over looked and need a 2nd pair of eyes to see.</p> <p>here is my code.</p> <p>&nbsp;</p> <p>=============================</p> <font color="#0000ff" size="2"> <p>Protected</font><font size="2"> </font><font color="#0000ff" size="2">Sub</font><font size="2"> bt__Upload_Click(</font><font color="#0000ff" size="2">ByVal</font><font size="2"> sender </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">Object</font><font size="2">, </font><font color="#0000ff" size="2">ByVal</font><font size="2"> e </font><font color="#0000ff" size="2">As</font><font size="2"> System.EventArgs) </font><font color="#0000ff" size="2">Handles</font><font size="2"> bt_UpLoad.Click</p> <p></font><font color="#008000" size="2">' first, check whether a valid full-sized image was uploaded</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">If</font><font size="2"> FullSizedImage.PostedFile </font><font color="#0000ff" size="2">Is</font><font size="2"> </font><font color="#0000ff" size="2">Nothing</font><font size="2"> </font><font color="#0000ff" size="2">Then</p> </font><font size="2"> <p></font><font color="#008000" size="2">'Message.Text = &quot;The full-sized image file does not exist.&quot;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Else</font><font size="2"> </font><font color="#008000" size="2">' full sized image was uploaded</p> <p>&nbsp;</p> <p>&nbsp;</p> </font><font size="2"> <p></font><font color="#008000" size="2">' just working on the filenames</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> FilenameAndExtension </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = System.IO.Path.GetFileName(FullSizedImage.PostedFile.FileName)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> IndexOfDot </font> <font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">Integer</font><font size="2"> = FilenameAndExtension.LastIndexOf(</font><font color="#800000" size="2">&quot;.&quot;</font><font size="2">)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> FilenameOnly </font> <font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = FilenameAndExtension.Substring(0, IndexOfDot)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> ExtensionOnly </font> <font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = FilenameAndExtension.Substring(IndexOfDot &#43; 1, FilenameAndExtension.Length - IndexOfDot - 1)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> ThumbnailFilename </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = FilenameOnly &amp; </font><font color="#800000" size="2">&quot;-t.&quot;</font><font size="2"> &amp; ExtensionOnly</p> <p></font><font color="#008000" size="2">' let's save the main image</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> LocationToSave = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Full/&quot;</font><font size="2">)</p> <p>FullSizedImage.PostedFile.SaveAs(LocationToSave &#43; FilenameAndExtension)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> Full </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = </font><font color="#800000" size="2">&quot;http://exiled-studios.com/images/Portfolio/Full/&quot;</font><font size="2"> &amp; FullSizedImage.FileName &amp; </font><font color="#800000" size="2">&quot;&quot;</p> </font><font size="2"> <p></font><font color="#008000" size="2">' to start, we'll load up full-sized image as an Image file</p> </font><font size="2"> <p></font><font color="#008000" size="2">' (previously, it was just any old file ... could have been a Word document for all we know)</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> FullSizePhoto </font> <font color="#0000ff" size="2">As</font><font size="2"> System.Drawing.Image</p> <p>FullSizePhoto = System.Drawing.Image.FromFile(LocationToSave &#43; FilenameAndExtension)</p> <p>&nbsp;</p> <p></font><font color="#008000" size="2">' now that we have it as an image file, we can create a thumbnail easily</p> </font><font size="2"> <p></font><font color="#008000" size="2">' first, we need to be prepared for a problem</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> dummyCallBack </font> <font color="#0000ff" size="2">As</font><font size="2"> System.Drawing.Image.GetThumbnailImageAbort</p> <p>dummyCallBack = </font><font color="#0000ff" size="2">New</font><font size="2"> System.Drawing.Image.GetThumbnailImageAbort(</font><font color="#0000ff" size="2">AddressOf</font><font size="2"> CallBack)</p> <p></font><font color="#008000" size="2">' have gotten ready for a problem, let's create the thumbnail</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> ThumbnailPhoto </font><font color="#0000ff" size="2">As</font><font size="2"> System.Drawing.Image</p> <p>ThumbnailPhoto = FullSizePhoto.GetThumbnailImage(200, 200, dummyCallBack, IntPtr.Zero)</p> <p>&nbsp;</p> <p></font><font color="#008000" size="2">' release our hold on the full-sized image</p> </font><font size="2"> <p>FullSizePhoto.Dispose()</p> <p></font><font color="#008000" size="2">' save the thumbnail</p> </font><font size="2"> <p>ThumbnailPhoto.Save(LocationToSave &#43; ThumbnailFilename, ImageFormat.Jpeg)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> Thumb </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = </font><font color="#800000" size="2">&quot;http://exiled-studios.com/images/Portfolio/Thumb/&quot;</font><font size="2"> &amp; ThumbnailFilename &amp; </font><font color="#800000" size="2">&quot;&quot;</p> </font><font size="2"> <p></font><font color="#008000" size="2">' success!</p> </font><font size="2"> <p></font><font color="#008000" size="2">'upload file paaths to database</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> strConn </font> <font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = </font><font color="#800000" size="2">&quot;Server=Server; Database=database; User ID=Username; Password=Password; Integrated Security=False&quot;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> MySQL </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">String</font><font size="2"> = </font><font color="#800000" size="2">&quot;Insert into tbl_Gallery(FullPath, ThumbPath, PostedBy, DateSubmitted) &quot;</font><font size="2"> &amp; _</p> <p></font><font color="#800000" size="2">&quot;Values (@FullPath, @ThumbPath, @PostedBy, @DateSubmitted)&quot;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> MyConn </font> <font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">New</font><font size="2"> Data.SqlClient.SqlConnection(strConn)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> Cmd </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">New</font><font size="2"> Data.SqlClient.SqlCommand(MySQL, MyConn)</p> <p></font><font color="#0000ff" size="2">With</font><font size="2"> Cmd.Parameters</p> <p>.Add(</font><font color="#0000ff" size="2">New</font><font size="2"> Data.SqlClient.SqlParameter(</font><font color="#800000" size="2">&quot;@FullPath&quot;</font><font size="2">, Full))</p> <p>.Add(</font><font color="#0000ff" size="2">New</font><font size="2"> Data.SqlClient.SqlParameter(</font><font color="#800000" size="2">&quot;@ThumbPath&quot;</font><font size="2">, Thumb))</p> <p>.Add(</font><font color="#0000ff" size="2">New</font><font size="2"> Data.SqlClient.SqlParameter(</font><font color="#800000" size="2">&quot;@PostedBy&quot;</font><font size="2">, User.Identity.Name))</p> <p>.Add(</font><font color="#0000ff" size="2">New</font><font size="2"> Data.SqlClient.SqlParameter(</font><font color="#800000" size="2">&quot;@DateSubmitted&quot;</font><font size="2">, </font><font color="#0000ff" size="2">Date</font><font size="2">.Now))</p> <p></font><font color="#0000ff" size="2">End</font><font size="2"> </font><font color="#0000ff" size="2">With</p> </font><font size="2"> <p>MyConn.Open()</p> <p>Cmd.ExecuteNonQuery()</p> <p>MyConn.Close()</p> <p>MyConn.Dispose()</p> <p></font><font color="#008000" size="2">'Message.Text = &quot;The photo and its thumbnail has been saved.&quot;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">End</font><font size="2"> </font><font color="#0000ff" size="2">If</font><font size="2"> </font><font color="#008000" size="2">' was full sized image uploaded?</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">End</font><font size="2"> </font><font color="#0000ff" size="2">Sub</p> <p>&nbsp;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Public</font><font size="2"> </font><font color="#0000ff" size="2">Function</font><font size="2"> CallBack() </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">Boolean</p> <p>&nbsp;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">Return</font><font size="2"> </font><font color="#0000ff" size="2">False</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">End</font><font size="2"> </font><font color="#0000ff" size="2">Function</font></p> <p><font color="#0000ff" size="2">============================================</p> </font> 2007-03-08T02:21:11-05:001610712http://forums.asp.net/p/1084216/1610712.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. <p>try it out<br> &nbsp;</p> <pre class="prettyprint">If contentLength &lt;&gt; 0 Then Dim fileName As String = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf(&quot;\&quot;) &#43; 1) Dim filePath As String = Server.MapPath(&quot;~/upload/PhotoAlbum/Products/&quot; &amp; Product_ID &amp; &quot;/Large/&quot; &amp; ObjImage.GetImageId &amp; &quot;.jpg&quot;) 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(&quot;Product_ID&quot;)) 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(&quot;Copyright &quot; &amp; DateTime.Now.Year, New Font(&quot;Verdana&quot;, 12, FontStyle.Bold), Brushes.White, New PointF(0, (bitmap_Large.Height / 2) - 122), stringFormat) bitmap_Large.Save(MapPath(&quot;~/upload/PhotoAlbum/Products/&quot; &amp; Product_ID &amp; &quot;/Large/&quot; &amp; ObjImage.GetImageId &amp; &quot;.jpg&quot;), image.RawFormat) bitmap_Thumb.Save(MapPath(&quot;~/upload/PhotoAlbum/Products/&quot; &amp; Product_ID &amp; &quot;/thumb/&quot; &amp; ObjImage.GetImageId &amp; &quot;.jpg&quot;), image.RawFormat) BindData(Request.QueryString(&quot;Product_ID&quot;)) End If</pre>&nbsp;<br> <p>&nbsp;cheers</p> 2007-03-08T05:35:22-05:001610727http://forums.asp.net/p/1084216/1610727.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. <p>Hmm ok thanks. Ill give that a try.</p> 2007-03-08T05:44:24-05:001610730http://forums.asp.net/p/1084216/1610730.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. I think that you are saving the images in folder........... <font color="#800000"> Images/Portfolio/Full.....<br> </font><font color="#000000">&nbsp;where as you are saving different path into the Database i.e </font><font color="#800000">images/Portfolio/Thumb<br> <br> <font color="#000000">I think that this might be the problem.....</font></font> 2007-03-08T05:46:52-05:001610756http://forums.asp.net/p/1084216/1610756.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Dhaliwal</h4> I think that you are saving the images in folder........... <font color="#800000"> Images/Portfolio/Full.....<br> </font><font color="#000000">&nbsp;where as you are saving different path into the Database i.e </font><font color="#800000">images/Portfolio/Thumb<br> <br> <font color="#000000">I think that this might be the problem.....</font></font></blockquote> <p></p> <p>&nbsp;</p> <p>Thats what I was thinking and <br> I believe that peice of code is the culprit</p> <p>&quot; <font color="#0000ff">Dim</font><font size="2"> LocationToSave = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Full/&quot;</font><font size="2">)&nbsp;&nbsp; &quot;</font></p> <p>What I am unsure of is how to modify or add to that to save to both places.&nbsp;&nbsp; thumb and full. [:S]</p> 2007-03-08T06:01:42-05:001610768http://forums.asp.net/p/1084216/1610768.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. make it like this <br> <br> &nbsp;<pre class="prettyprint">Dim bitmap_Thumb As Bitmap = New Bitmap(image, 118, 118) bitmap_Thumb.Save(MapPath(&quot;~/Images/Portfolio/Thumb/&quot;), image.RawFormat)</pre>&nbsp;cheers<br> 2007-03-08T06:07:51-05:001610777http://forums.asp.net/p/1084216/1610777.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. <p>Ok. I was 1/3 right <br> <br> here is what I think the rest of my problem is and if any one could help me out here on this.</p> <p>&nbsp;So here is where the upload is supposed to be sending the full image. <font color="#0000ff" size="2"> </p> <p>Dim</font><font size="2"> LocationToSave = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Full/&quot;</font><font size="2">)</font></p> <font size="2"><font size="2"> <p>&nbsp;</p> <p>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. </font><font size="2"></p> <font color="#0000ff" size="2"> <p>Dim</font><font size="2"> ThumbnailPhoto </font><font color="#0000ff" size="2">As</font><font size="2"> System.Drawing.Image</p> </font></font></font><font size="2"> <p>ThumbnailPhoto.Save(<strong>LocationToSave</strong> &#43; ThumbnailFilename, ImageFormat.Jpeg)</p> <p>&nbsp;</p> <p>.......</p> <p>What do I need to add to sepurate the paths into full and thumb like I need. </p> <p>I checked my database and the paths are being saved correctly but the thumb is not going to the same directory.</p> </font> 2007-03-08T06:13:21-05:001610790http://forums.asp.net/p/1084216/1610790.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. I think you are just confusing it....... Just try this<br> <br> <font color="#0000ff">Dim</font><font size="2"> LocationToSaveFull = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Full/&quot;</font><font size="2">) <br> FullSizedImage.PostedFile.SaveAs(LocationToSaveFull &#43; FilenameAndExtension) <p>&nbsp;</p> <p><br> </font><font color="#008000">// while saving ThumbNail<br> </font><font color="#0000ff">Dim</font><font size="2"> LocationToSaveThumb = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Thumb/&quot;</font><font size="2">) <br> </font>ThumbnailPhoto.Save(LocationToSaveThumb &#43; ThumbnailFilename, ImageFormat.Jpeg)<br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> </p> 2007-03-08T06:24:30-05:001610791http://forums.asp.net/p/1084216/1610791.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. <blockquote><span class="icon-blockquote"></span> <h4>aghausman12</h4> make it like this <br> <br> &nbsp;<pre class="prettyprint">Dim bitmap_Thumb As Bitmap = New Bitmap(image, 118, 118) bitmap_Thumb.Save(MapPath(&quot;~/Images/Portfolio/Thumb/&quot;), image.RawFormat)</pre> <p>&nbsp;cheers<br> </p> </blockquote> <p></p> <p>&nbsp;</p> <p>Thank you didn't see this post untill I Got done with my last. one. testing now.</p> <p>&nbsp;</p> <p>Ok the code you gave didn't work. but!! :D&nbsp; it gave me the clue I needed to get it working. basically. </p> <p>I did this <br> <font color="#0000ff" size="2"></p> <p>&quot;'Dim</font><font size="2"> LocationToSaveThumb = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Thumb/&quot;</font><font size="2">)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> ThumbnailPhoto </font><font color="#0000ff" size="2">As</font><font size="2"> System.Drawing.Image</p> <p>ThumbnailPhoto = FullSizePhoto.GetThumbnailImage(200, 200, dummyCallBack, IntPtr.Zero&quot;&quot;</p> <p>&nbsp;</p> <p>It works perfectly now. Thank you very very much !!!!</p> </font> 2007-03-08T06:24:35-05:001610793http://forums.asp.net/p/1084216/1610793.aspx/1?Re+Thumb+nail+problem+Re: Thumb nail problem. I think you are just confusing it....... Just try this<br> <br> <font color="#0000ff">Dim</font><font size="2"> LocationToSaveFull = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Full/&quot;</font><font size="2">) <br> FullSizedImage.PostedFile.SaveAs(LocationToSaveFull &#43; FilenameAndExtension) <p>&nbsp;</p> <p><br> </font><font color="#008000">// while saving ThumbNail<br> </font><font color="#0000ff">Dim</font><font size="2"> LocationToSaveThumb = Server.MapPath(</font><font color="#800000" size="2">&quot;~/Images/Portfolio/Thumb/&quot;</font><font size="2">) <br> </font>ThumbnailPhoto.Save(LocationToSaveThumb &#43; ThumbnailFilename, ImageFormat.Jpeg)<br> <br> <br> </p> 2007-03-08T06:24:51-05:00