GDI+ Resizing image problem

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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(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 Guest

  2. Similar Questions and Discussions

    1. Image Resizing With A Catch
      So I'm running ColdFusion on GoDaddy Linux Hosting (booo, I know, but it's cheap and I'm a poor college student that likes to have lots of domains)....
    2. image resizing
      Hi, Is there a toggle switch in InDesign which enables one to resize an image using the pick tool without cropping it? -Paul
    3. Resizing a image!
      Hello, I just started with PHP. And I have made a code for uploading images. Now I wil resize the image also to a tumbnail, but when I search...
    4. Resizing an image...
      I have a jpg that when clicked upon opens to about 4 x 6 on screen. How can I resize this photo so that the maximum it will only open to is a 3" x 4"...
    5. Resizing high res image smaller results in blurred image
      Hi there, I have a high res logo in PSD format (around 1500px x 1500px) but when I resize it to around 300px x 300px the resulting image is not...
  3. #2

    Default 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...
    [url]http://www.dotnet247.com/247reference/msgs/25/128742.aspx[/url]

    "James A Taber" <icecool_6@hotmail.com> wrote in message
    news:eB7LHhuODHA.4024@tk2msftngp13.phx.gbl...
    > 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 Guest

  4. #3

    Default Re: GDI+ Resizing image problem

    Hi,

    use :
    oGrapic.InterpolationMode =
    System.Drawing.Drawing2D.InterpolationMode.HighQua lityBilinear
    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] [url]http://www.developersdex.com/gurus/code/599.asp[/url]

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  5. #4

    Default 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@hotmail.com> wrote in message
    news:O3234muODHA.1072@TK2MSFTNGP10.phx.gbl...
    > 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...
    > [url]http://www.dotnet247.com/247reference/msgs/25/128742.aspx[/url]
    >
    > "James A Taber" <icecool_6@hotmail.com> wrote in message
    > news:eB7LHhuODHA.4024@tk2msftngp13.phx.gbl...
    > > 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 Guest

  6. #5

    Default 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:e9nHaF3ODHA.2460@TK2MSFTNGP10.phx.gbl...
    > 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.HighQualityBic ubic
    > 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" <icecool_6@hotmail.com> wrote in message
    > news:uEMVn1wODHA.1608@TK2MSFTNGP11.phx.gbl...
    > > 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@hotmail.com> wrote in message
    > > news:O3234muODHA.1072@TK2MSFTNGP10.phx.gbl...
    > > > 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...
    > > > [url]http://www.dotnet247.com/247reference/msgs/25/128742.aspx[/url]
    > > >
    > > > "James A Taber" <icecool_6@hotmail.com> wrote in message
    > > > news:eB7LHhuODHA.4024@tk2msftngp13.phx.gbl...
    > > > > 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 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139