GDI+ Resizing image problem

Discussion in 'ASP .Net' started by James A Taber, Jun 25, 2003.

  1. Problem resizing image.(JPG)

    If i try to resize an img with horisontal=150 and vertical resolution=150
    The quality of the target image is dramatically reduced. Source code is
    provided below.

    How can i solve this? What am i doing wrong?

    Thanx in advance
    -James A Taber

    Public Sub ResizeImage(ByVal sSourcePath As String, ByVal sTargetPath As
    String)
    Dim fs As FileStream
    Dim gImageIn As Image
    Dim gImageInFormat As Object

    Try
    fs = New FileStream(sSourcePath, FileMode.Open, FileAccess.Read)
    gImageIn = Image.FromStream(fs)

    gImageInFormat = gImageIn.RawFormat
    Dim gImageOut As New System.Drawing.Bitmap(gImageIn, 350, 262)

    gImageOut.Save(sTargetPath, gImageInFormat)

    Catch
    Throw
    Finally
    fs.Close()
    gImageIn.Dispose()
    End Try

    End Sub
     
    James A Taber, Jun 25, 2003
    #1
    1. Advertising

  2. James A Taber

    PJ Guest

    ahh...I have a method at work to create quality thumbnails, but I am at
    home...

    here is a discussion to help you get started...it's where i did...
    http://www.dotnet247.com/247reference/msgs/25/128742.aspx

    "James A Taber" <> wrote in message
    news:...
    > Problem resizing image.(JPG)
    >
    > If i try to resize an img with horisontal=150 and vertical resolution=150
    > The quality of the target image is dramatically reduced. Source code is
    > provided below.
    >
    > How can i solve this? What am i doing wrong?
    >
    > Thanx in advance
    > -James A Taber
    >
    > Public Sub ResizeImage(ByVal sSourcePath As String, ByVal sTargetPath As
    > String)
    > Dim fs As FileStream
    > Dim gImageIn As Image
    > Dim gImageInFormat As Object
    >
    > Try
    > fs = New FileStream(sSourcePath, FileMode.Open,

    FileAccess.Read)
    > gImageIn = Image.FromStream(fs)
    >
    > gImageInFormat = gImageIn.RawFormat
    > Dim gImageOut As New System.Drawing.Bitmap(gImageIn, 350, 262)
    >
    > gImageOut.Save(sTargetPath, gImageInFormat)
    >
    > Catch
    > Throw
    > Finally
    > fs.Close()
    > gImageIn.Dispose()
    > End Try
    >
    > End Sub
    >
    >
     
    PJ, Jun 25, 2003
    #2
    1. Advertising

  3. James A Taber

    Natty Gur Guest

    Hi,

    use :
    oGrapic.InterpolationMode =
    System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear
    oGrapic.DrawImage(oBmp, New Rectangle(0, 0, oTxtBmp.Width,
    oTxtBmp.Height), _
    0, _
    0, _
    oBmp.Width, _
    oBmp.Height, _
    GraphicsUnit.Pixel)

    you can also refer to this sample[1] that create dynamic buttons by the
    button text length.

    [1] http://www.developersdex.com/gurus/code/599.asp

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Natty Gur, Jun 25, 2003
    #3
  4. I have tried to figue it out ... But have until now not been able to do
    that. Could you provide me some sample code?

    I would be greatful for any help.

    Thanx

    James A Taber



    "PJ" <> wrote in message
    news:...
    > ahh...I have a method at work to create quality thumbnails, but I am at
    > home...
    >
    > here is a discussion to help you get started...it's where i did...
    > http://www.dotnet247.com/247reference/msgs/25/128742.aspx
    >
    > "James A Taber" <> wrote in message
    > news:...
    > > Problem resizing image.(JPG)
    > >
    > > If i try to resize an img with horisontal=150 and vertical

    resolution=150
    > > The quality of the target image is dramatically reduced. Source code is
    > > provided below.
    > >
    > > How can i solve this? What am i doing wrong?
    > >
    > > Thanx in advance
    > > -James A Taber
    > >
    > > Public Sub ResizeImage(ByVal sSourcePath As String, ByVal sTargetPath As
    > > String)
    > > Dim fs As FileStream
    > > Dim gImageIn As Image
    > > Dim gImageInFormat As Object
    > >
    > > Try
    > > fs = New FileStream(sSourcePath, FileMode.Open,

    > FileAccess.Read)
    > > gImageIn = Image.FromStream(fs)
    > >
    > > gImageInFormat = gImageIn.RawFormat
    > > Dim gImageOut As New System.Drawing.Bitmap(gImageIn, 350,

    262)
    > >
    > > gImageOut.Save(sTargetPath, gImageInFormat)
    > >
    > > Catch
    > > Throw
    > > Finally
    > > fs.Close()
    > > gImageIn.Dispose()
    > > End Try
    > >
    > > End Sub
    > >
    > >

    >
    >
     
    James A Taber, Jun 25, 2003
    #4
  5. Tank you, This is absolutely perfect!
    Thanks for all you help and time.

    :)
    James A Taber

    "PJ" <> wrote in message
    news:...
    > here's a method i use...sorry it's VB...i'm forced to code in this god

    awful
    > syntax right now...
    >
    > Private Shared Function ScaleFile(ByVal img As Image, ByVal newSize As

    Size)
    > As Byte()
    >
    > Dim newImg As Image = New Bitmap(newSize.Width, newSize.Height,
    > img.PixelFormat)
    > Dim graphic As Graphics = Graphics.FromImage(newImg)
    > graphic.CompositingQuality() =
    > Drawing.Drawing2D.CompositingQuality.HighQuality
    > graphic.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
    > graphic.InterpolationMode =
    > Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
    > Dim rect As New Rectangle(0, 0, newSize.Width, newSize.Height)
    > graphic.DrawImage(img, rect)
    > Dim ms As New MemoryStream()
    > newImg.Save(ms, img.RawFormat)
    > Dim bytes As Byte() = ms.ToArray()
    > ms.Close()
    > Return bytes
    >
    > End Function
    >
    > "James A Taber" <> wrote in message
    > news:...
    > > I have tried to figue it out ... But have until now not been able to do
    > > that. Could you provide me some sample code?
    > >
    > > I would be greatful for any help.
    > >
    > > Thanx
    > >
    > > James A Taber
    > >
    > >
    > >
    > > "PJ" <> wrote in message
    > > news:...
    > > > ahh...I have a method at work to create quality thumbnails, but I am

    at
    > > > home...
    > > >
    > > > here is a discussion to help you get started...it's where i did...
    > > > http://www.dotnet247.com/247reference/msgs/25/128742.aspx
    > > >
    > > > "James A Taber" <> wrote in message
    > > > news:...
    > > > > Problem resizing image.(JPG)
    > > > >
    > > > > If i try to resize an img with horisontal=150 and vertical

    > > resolution=150
    > > > > The quality of the target image is dramatically reduced. Source code

    > is
    > > > > provided below.
    > > > >
    > > > > How can i solve this? What am i doing wrong?
    > > > >
    > > > > Thanx in advance
    > > > > -James A Taber
    > > > >
    > > > > Public Sub ResizeImage(ByVal sSourcePath As String, ByVal

    sTargetPath
    > As
    > > > > String)
    > > > > Dim fs As FileStream
    > > > > Dim gImageIn As Image
    > > > > Dim gImageInFormat As Object
    > > > >
    > > > > Try
    > > > > fs = New FileStream(sSourcePath, FileMode.Open,
    > > > FileAccess.Read)
    > > > > gImageIn = Image.FromStream(fs)
    > > > >
    > > > > gImageInFormat = gImageIn.RawFormat
    > > > > Dim gImageOut As New System.Drawing.Bitmap(gImageIn,

    350,
    > > 262)
    > > > >
    > > > > gImageOut.Save(sTargetPath, gImageInFormat)
    > > > >
    > > > > Catch
    > > > > Throw
    > > > > Finally
    > > > > fs.Close()
    > > > > gImageIn.Dispose()
    > > > > End Try
    > > > >
    > > > > End Sub
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    James A Taber, Jun 26, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Vaughn

    GDI+ and Image Maps

    Kevin Vaughn, Jul 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    425
    Kevin Vaughn
    Jul 11, 2003
  2. Sinora
    Replies:
    1
    Views:
    855
    David White
    Nov 11, 2003
  3. Robin van de Water [synthesiSFactory]

    GDI+ is not properly initialized (internal GDI+ error).

    Robin van de Water [synthesiSFactory], Jan 10, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    1,365
    Robin van de Water [synthesiSFactory]
    Jan 10, 2007
  4. Pil (Trustworthy from Experience)

    Resizing a div by resizing its borders

    Pil (Trustworthy from Experience), Apr 18, 2009, in forum: Javascript
    Replies:
    9
    Views:
    360
    Proper
    Apr 21, 2009
  5. Proper
    Replies:
    0
    Views:
    205
    Proper
    Apr 18, 2009
Loading...

Share This Page