locked
TGA (targa) Files RRS feed

  • Question

  • User1710849301 posted
    Anybody have any experience working with Targa (TGA) files? I want to be able to upload these, have them "convert" to a (resized) jpeg for display on the web. I can't seem to get this to work w/ Targa (TGA) files... dim img as System.Drawing.Image dim imgName = Pics(MakeValid(lblP.Text)) dim firstChar = imgName.SubString(0,1) If (firstChar = "/") OR (firstChar = "\") Then imgName = Replace(imgName,firstChar,Nothing,1) End If imgpath = Server.MapPath(imgName) img = System.Drawing.Image.FromFile(imgpath, True) imgH = img.Height imgW = img.Width If imgW > max then dim delW as integer = imgW - max dim SF as Double SF = max / imgW imgW *= SF imgH *= SF End If output += "

    " & _ "

    " img.Dispose()
    Wednesday, November 17, 2004 10:50 AM

All replies

  • User1710849301 posted
    sorry... posted the wrong peice of code... here's the right stuff... dim strFile As String = Server.Mappath(Request.Querystring("Img")) dim ImgW As Integer = CInt(Request.QueryString("W")) dim ImgH As Integer = CInt(Request.QueryString("H")) dim FS as New FileStream(strFile, FileMode.Open, FileAccess.Read) dim Img As System.Drawing.Image = System.Drawing.Image.FromStream(FS) FS.Close() dim Thumbnail As New System.Drawing.Bitmap(ImgW, ImgH, PixelFormat.Format24BppRGB) dim G As Graphics = Graphics.FromImage(Thumbnail) If (Img.width/Img.height) < (ImgW/ImgH) Then 'portrait image processing G.DrawImage(Img, New Rectangle(0,0,ImgW, ImgH), _ New Rectangle(0,0,Img.Width,Img.Width / ImgW*ImgH), GraphicsUnit.Pixel) Else 'landscape image processing G.DrawImage(Img, New Rectangle(0,0,ImgW, ImgH), _ New Rectangle(0,0,Img.Height/ImgH * ImgW,Img.Height), GraphicsUnit.Pixel) End If If Img.RawFormat.Equals(Imaging.Imageformat.Gif) Then Response.ContentType = "image/gif" Else Response.ContentType = "image/jpeg" End if Thumbnail.Save(Response.OutputStream, Img.RawFormat) Thumbnail.Dispose()
    Wednesday, November 17, 2004 2:06 PM
  • User1710849301 posted
    So I guess there's not really anything that can be done with TGA files eh?
    Thursday, December 16, 2004 12:38 PM
  • User861366575 posted
    I never found a solution for this either. I ended up getting a 3rd party image conversion program that supported command line execution. There are a bunch out there (google). Shared strProgram As String = "C:\Progra~1\Advanc~1\abc.exe" Public Shared Function ConvertToFile(ByVal strImagePath As String, ByVal strSavePath As String) As Image Dim tmp As String = Library.FileUtility.ParseExtensionFromPath(strSavePath) strSavePath = Replace(strSavePath, "." & tmp, ".jpg") Shell(strProgram & " " & strImagePath & " /jpg /convert=" & strSavePath) End Function
    Thursday, February 17, 2005 11:34 AM
  • User1710849301 posted
    hmm... i feared as much. Thank you VERY much for the reply. BTW did you run this as/from a web app also?
    Monday, March 14, 2005 12:44 AM
  • User861366575 posted
    Yes. The code from above is what I am currently using in an intranet web app. The program I ended up using was "Advanced Batch Converter" (abc.exe). The only downside to using TGA, is the files are usually pretty large (around 2mb for me). So unless you are on the same network or computer, the upload time can be an annoyance.
    Monday, March 14, 2005 8:27 AM