GDI+ Resizing image problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James A Taber

    GDI+ Resizing image problem

    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(ByV al sSourcePath As String, ByVal sTargetPath As
    String)
    Dim fs As FileStream
    Dim gImageIn As Image
    Dim gImageInFormat As Object

    Try
    fs = New FileStream(sSou rcePath, FileMode.Open, FileAccess.Read )
    gImageIn = Image.FromStrea m(fs)

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

    gImageOut.Save( sTargetPath, gImageInFormat)

    Catch
    Throw
    Finally
    fs.Close()
    gImageIn.Dispos e()
    End Try

    End Sub


  • PJ

    #2
    Re: GDI+ Resizing image problem

    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...


    "James A Taber" <icecool_6@hotm ail.com> wrote in message
    news:eB7LHhuODH A.4024@tk2msftn gp13.phx.gbl...[color=blue]
    > 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(ByV al sSourcePath As String, ByVal sTargetPath As
    > String)
    > Dim fs As FileStream
    > Dim gImageIn As Image
    > Dim gImageInFormat As Object
    >
    > Try
    > fs = New FileStream(sSou rcePath, FileMode.Open,[/color]
    FileAccess.Read )[color=blue]
    > gImageIn = Image.FromStrea m(fs)
    >
    > gImageInFormat = gImageIn.RawFor mat
    > Dim gImageOut As New System.Drawing. Bitmap(gImageIn , 350, 262)
    >
    > gImageOut.Save( sTargetPath, gImageInFormat)
    >
    > Catch
    > Throw
    > Finally
    > fs.Close()
    > gImageIn.Dispos e()
    > End Try
    >
    > End Sub
    >
    >[/color]


    Comment

    • Natty Gur

      #3
      Re: GDI+ Resizing image problem

      Hi,

      use :
      oGrapic.Interpo lationMode =
      System.Drawing. Drawing2D.Inter polationMode.Hi ghQualityBiline ar
      oGrapic.DrawIma ge(oBmp, New Rectangle(0, 0, oTxtBmp.Width,
      oTxtBmp.Height) , _
      0, _
      0, _
      oBmp.Width, _
      oBmp.Height, _
      GraphicsUnit.Pi xel)

      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!

      Comment

      • James A Taber

        #4
        Re: GDI+ Resizing image problem

        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" <pjwalNOSPAM@ho tmail.com> wrote in message
        news:O3234muODH A.1072@TK2MSFTN GP10.phx.gbl...[color=blue]
        > 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/247referenc...25/128742.aspx
        >
        > "James A Taber" <icecool_6@hotm ail.com> wrote in message
        > news:eB7LHhuODH A.4024@tk2msftn gp13.phx.gbl...[color=green]
        > > Problem resizing image.(JPG)
        > >
        > > If i try to resize an img with horisontal=150 and vertical[/color][/color]
        resolution=150[color=blue][color=green]
        > > 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(ByV al sSourcePath As String, ByVal sTargetPath As
        > > String)
        > > Dim fs As FileStream
        > > Dim gImageIn As Image
        > > Dim gImageInFormat As Object
        > >
        > > Try
        > > fs = New FileStream(sSou rcePath, FileMode.Open,[/color]
        > FileAccess.Read )[color=green]
        > > gImageIn = Image.FromStrea m(fs)
        > >
        > > gImageInFormat = gImageIn.RawFor mat
        > > Dim gImageOut As New System.Drawing. Bitmap(gImageIn , 350,[/color][/color]
        262)[color=blue][color=green]
        > >
        > > gImageOut.Save( sTargetPath, gImageInFormat)
        > >
        > > Catch
        > > Throw
        > > Finally
        > > fs.Close()
        > > gImageIn.Dispos e()
        > > End Try
        > >
        > > End Sub
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • James A Taber

          #5
          Re: GDI+ Resizing image problem

          Tank you, This is absolutely perfect!
          Thanks for all you help and time.

          :-)
          James A Taber

          "PJ" <pjwal@hotmail. com> wrote in message
          news:e9nHaF3ODH A.2460@TK2MSFTN GP10.phx.gbl...[color=blue]
          > here's a method i use...sorry it's VB...i'm forced to code in this god[/color]
          awful[color=blue]
          > syntax right now...
          >
          > Private Shared Function ScaleFile(ByVal img As Image, ByVal newSize As[/color]
          Size)[color=blue]
          > As Byte()
          >
          > Dim newImg As Image = New Bitmap(newSize. Width, newSize.Height,
          > img.PixelFormat )
          > Dim graphic As Graphics = Graphics.FromIm age(newImg)
          > graphic.Composi tingQuality() =
          > Drawing.Drawing 2D.CompositingQ uality.HighQual ity
          > graphic.Smoothi ngMode = Drawing.Drawing 2D.SmoothingMod e.HighQuality
          > graphic.Interpo lationMode =
          > Drawing.Drawing 2D.Interpolatio nMode.HighQuali tyBicubic
          > Dim rect As New Rectangle(0, 0, newSize.Width, newSize.Height)
          > graphic.DrawIma ge(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" <icecool_6@hotm ail.com> wrote in message
          > news:uEMVn1wODH A.1608@TK2MSFTN GP11.phx.gbl...[color=green]
          > > 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" <pjwalNOSPAM@ho tmail.com> wrote in message
          > > news:O3234muODH A.1072@TK2MSFTN GP10.phx.gbl...[color=darkred]
          > > > ahh...I have a method at work to create quality thumbnails, but I am[/color][/color][/color]
          at[color=blue][color=green][color=darkred]
          > > > home...
          > > >
          > > > here is a discussion to help you get started...it's where i did...
          > > > http://www.dotnet247.com/247referenc...25/128742.aspx
          > > >
          > > > "James A Taber" <icecool_6@hotm ail.com> wrote in message
          > > > news:eB7LHhuODH A.4024@tk2msftn gp13.phx.gbl...
          > > > > Problem resizing image.(JPG)
          > > > >
          > > > > If i try to resize an img with horisontal=150 and vertical[/color]
          > > resolution=150[color=darkred]
          > > > > The quality of the target image is dramatically reduced. Source code[/color][/color]
          > is[color=green][color=darkred]
          > > > > provided below.
          > > > >
          > > > > How can i solve this? What am i doing wrong?
          > > > >
          > > > > Thanx in advance
          > > > > -James A Taber
          > > > >
          > > > > Public Sub ResizeImage(ByV al sSourcePath As String, ByVal[/color][/color][/color]
          sTargetPath[color=blue]
          > As[color=green][color=darkred]
          > > > > String)
          > > > > Dim fs As FileStream
          > > > > Dim gImageIn As Image
          > > > > Dim gImageInFormat As Object
          > > > >
          > > > > Try
          > > > > fs = New FileStream(sSou rcePath, FileMode.Open,
          > > > FileAccess.Read )
          > > > > gImageIn = Image.FromStrea m(fs)
          > > > >
          > > > > gImageInFormat = gImageIn.RawFor mat
          > > > > Dim gImageOut As New System.Drawing. Bitmap(gImageIn ,[/color][/color][/color]
          350,[color=blue][color=green]
          > > 262)[color=darkred]
          > > > >
          > > > > gImageOut.Save( sTargetPath, gImageInFormat)
          > > > >
          > > > > Catch
          > > > > Throw
          > > > > Finally
          > > > > fs.Close()
          > > > > gImageIn.Dispos e()
          > > > > End Try
          > > > >
          > > > > End Sub
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...