Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, just a quick question. I'm tryi

Status
Not open for further replies.

kennyaidan

Programmer
Apr 9, 2003
54
IE
Hi, just a quick question. I'm trying to create thumbnails from full images. The code is working fine except when it comes to actually naming the thumbnail.
The relevant parts of the code are as follows

'Get relevant details from previous form called "MyFile"

FileName.InnerHtml = MyFile.PostedFile.FileName
Dim strFileName as string = MyFile.PostedFile.FileName
FileContent.InnerHtml = MyFile.PostedFile.ContentType
FileSize.InnerHtml = MyFile.PostedFile.ContentLength

'Get the main image
Dim currentImage as System.Drawing.Image = System.Drawing.Image.FromFile(FileName.InnerHtml)

Dim thumbImage as System.Drawing.Image
'set the width and height of the new thumbnail
Dim Width as integer = 100
Dim Height as integer = 100
Dim myOutput As FileStream

'create thumbnail
thumbImage = currentImage.GetThumbnailImage(Width, Height, nothing, nothing)

myOutput = new FileStream(MapPath(strFileName), FileMode.Create, FileAccess.Write, FileShare.Write)

'save thumbnail
thumbImage.Save(myOutput, ImageFormat.Gif)
myOutput.Close()

My problem is that i want to save the files in the following format - if the main image is called example.gif, i want to save the thumbnail as example_thb.gif. However its the "MapPath(strFileName)" line of code that is the problem. It won't allow me to create a file name string similar to the following
MapPath(strFileName"_thb".gif),

I'm only a beginner asp.net programmer so any help would be grreatly appreciated
thanks
aidan
 
Dim ThumbNailPath As String = MapPath(strFileName)
ThumbnailPath=ThumbNailPath.Left(ThumbNailPath.Length - 4) & "_thb" & ThumbNailPath.Right(4)

should do the trick.

I'm getting the string from the mappath and then reading the left bit, adding in the _thb and then reading in the .extension part.

Craig
 
Thanks Craig
i tried running the code but i got an error stating the following

Compiler Error Message: BC30456: 'Left' is not a member of 'String'.

Line 54: ThumbnailPath=ThumbNailPath.Left(ThumbNailPath.Length - 4) & "_thb" & ThumbNailPath.Right(4)

I'm sure i have made a mistake by adding your code in wrongly, so here's my altered code

Dim strFileName1 = MyFile.PostedFile.FileName

thumbImage = currentImage.GetThumbnailImage(Width, Height, nothing, nothing)
Dim ThumbNailPath As String = MapPath(strFileName1)

ThumbnailPath=ThumbNailPath.Left(ThumbNailPath.Length - 4) & "_thb" & ThumbNailPath.Right(4)

myOutput = new FileStream(ThumbnailPath(thumbImage), FileMode.Create, FileAccess.Write, FileShare.Write)

thumbImage.Save(myOutput, ImageFormat.Gif)
myOutput.Close()

Can u see where i have gone wrong
thanks
aidan
 
Quite correct. Should have checked.

ThumbnailPath=ThumbNailPath.Substring(0,ThumbNailPath.Length - 4) & "_thb" & ThumbNailPath.SubString(ThumbNailPath.Length - 4,4)

is correct.

Craig
 
Craig thanks again that solved that problem but i still got an error message it stated that

Expression is not an array or a method, and cannot have an argument list.

Line 57: myOutput = new FileStream(ThumbnailPath(thumbImage), FileMode.Create, FileAccess.Write, FileShare.Write)

Here's the code again
thumbImage = currentImage.GetThumbnailImage(Width, Height, nothing, nothing)
Dim ThumbNailPath As String = MapPath(strFileName1)

ThumbnailPath=ThumbNailPath.Substring(0,ThumbNailPath.Length - 4) & "_thb" & ThumbNailPath.SubString(ThumbNailPath.Length - 4,4)

myOutput = new FileStream(ThumbnailPath(thumbImage), FileMode.Create, FileAccess.Write, FileShare.Write)

thumbImage.Save(myOutput, ImageFormat.Gif)
myOutput.Close()

Any ideas????
 
Not surprised.....

You are using the New constructor of the FileStream object wrongly.

myOutput = new FileStream(ThumbnailPath, FileMode.Create, FileAccess.Write, FileShare.Write)

opens the stream.

You really need to look at how to create a binary file for the stream objects. Can't help any further.

Craig
 
ok thanks anyway craig, i changed the code and i got a different error

Invalid path for MapPath 'C:\Inetpub\ A virtual path is expected.

where hello is the gif i'm trying to make a thumbnail out of. If anyone has any other ideas greatly appreciated
aidan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top