+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: Show image according to column width

  1. #1
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Show image according to column width

    hi
    is there is a way that image(of any size) can be shown properly(no distortions) according to table column size?

    VB.NET 2005

    Thanx
    Last edited by richyrich; December 11th, 2008 at 10:52 AM.

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Is this link any good for you?

    Clicky

  3. #3
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    thanx RR, let me have a look

  4. #4
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    ok i tried code from RR's link, i made this function
    Code:
        Public Shared Function CreateThumbnail(ByVal lcFilename As String, ByVal lnWidth As Integer, ByVal lnHeight As Integer) As Bitmap
            'http://www.west-wind.com/Weblog/posts/283.aspx
            Dim bmpOut As System.Drawing.Bitmap
            Try
                Dim loBMP As New Bitmap(lcFilename)
                Dim loFormat As ImageFormat = loBMP.RawFormat
    
                Dim lnRatio, lnTemp As Decimal
                Dim lnNewWidth As Integer = 0
                Dim lnNewHeight As Integer = 0
    
                'If image is smaller than a thumbnail, return it as such
                If loBMP.Width < lnWidth And loBMP.Height < lnHeight Then
                    Return loBMP
                End If
    
    
                If loBMP.Width > loBMP.Height Then
                    lnRatio = lnWidth / loBMP.Width
                    lnNewWidth = lnWidth
                    lnTemp = loBMP.Height * lnRatio
                    lnNewHeight = CInt(lnTemp)
    
                Else
                    lnRatio = lnHeight / loBMP.Height
                    lnNewHeight = lnHeight
                    lnTemp = loBMP.Width * lnRatio
                    lnNewWidth = CInt(lnTemp)
                End If
    
                bmpOut = New Bitmap(lnNewWidth, lnNewHeight)
                Dim g As Graphics = Graphics.FromImage(bmpOut)
                g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight)
                g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight)
                loBMP.Dispose()
    
            Catch ex As Exception
                'Return False
            End Try
    
            Return bmpOut
    
        End Function
    
    and calling it like
    Code:
    Dim bmp As Bitmap = CreateThumbnail(strImage, 150, 150)
    
    where strImage is a url coming from database.
    but now how do i show this image?
    i am using an .net image control.

    any ideas/suggestions??

  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    What does he do with it in the example?

    Could you save the bitmap as a file and then use the filename as the imageurl of an image control?

  6. #6
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    in the example, he saves it as a file, which i dont want.
    but he also streams it to the browser like (C# code)
    Code:
    Response.ContentType = "image/jpeg";
    bmp.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
    
    but i dont know how it works!!

    also i cant set bitmap as null
    i used it like this
    Code:
    Dim bmp As Bitmap = CGlobal.CreateThumbnail(strImage, 150, 150)
    Response.ContentType = "image/jpeg"
    bmp.Save(Response.OutputStream, ImageFormat.Jpeg)
    bmp.Dispose()
    
    but it gives me this error at red line
    Code:
    System.NullReferenceException: Object reference not set to an instance of an object.
    

  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I think the first parameter of the Save method should be the filename as a String

  8. #8
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Quote Originally Posted by richyrich View Post
    I think the first parameter of the Save method should be the filename as a String
    yes, but i think that wud be in case if the file is wished to be saved.

    I dont want to save the resized image, i just want to show it.

  9. #9
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    My guess is that your CreateThumbnail function is returning an error so the variable bmp never gets a value. Hence why you're getting the object reference error.

    I noticed you don't have code in the Catch section of the Try in your function. Try something in there to see if an error occurs, catch it and write it to the screen.

  10. #10
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    hmm, i get this error
    Code:
    System.ArgumentException: URI formats are not supported. at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck) at System.IO.Path.GetFullPathInternal(String path) at System.IO.Path.GetFullPath(String path) at System.Drawing.IntSecurity.UnsafeGetFullPath(String fileName) at System.Drawing.IntSecurity.DemandReadFileIO(String fileName)
    
    at this line
    Code:
    Dim loBMP As New Bitmap(strImage)
    

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. show datagrid even if empty
    By micky in forum .NET Development
    Replies: 3
    Last Post: December 9th, 2008, 08:39 AM
  2. Show Error Messages
    By micky in forum .NET Development
    Replies: 4
    Last Post: November 21st, 2008, 06:50 AM
  3. Good image resizer?
    By dr_rock in forum ASP Development
    Replies: 8
    Last Post: August 17th, 2008, 05:16 AM
  4. Dynamically Set Image Width
    By todd2006 in forum ASP Development
    Replies: 9
    Last Post: June 6th, 2008, 02:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO