Results 1 to 5 of 5

Thread: saving image to jpeg and resizing... works but...

  1. #1
    Kiweed
    Guest

    Question saving image to jpeg and resizing... works but...

    Previously in VB6 I managed to hook into a DLL created from the Intel graphics library.

    I had a speedy way to create thumbnails and to save a loaded images to a jpeg file where I can set the quality and other attributes.

    Now in vb.net this is very simple withbuilt in methods but...

    i) I do not know what type of sampling the thumbnail uses as the Intel library had a few choices depending on a tradeoff between speed and quality.

    ii) The jpeg save justs saves but does not seem to offer a control over the quality.

    Q. Is there a way to set the quality or other parameters when saving?

    There seems to be a lack of documentation or examples around that do any more than the basics.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    yeah using EncoderParameters


    Code:
    Dim imgCodecs() As ImageCodecInfo  = ImageCodecInfo.GetImageEncoders()
    
    Dim params As New EncoderParameters  = EncoderParameters(1)
    Dim quality As New EncoderParameter EncoderParameter(Encoder.Quality, 50)
    'Set quality to 50
    params.Param(0) = quality
    
    yourimage.Save("c:\output.jpg",imgCodecs(1), params)
    btw imgCodecs(1) means JPEG not sure what the other array values would be if you need other image types
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    oops..I knew I sghould have tested that...just kind of guessed..but there were some errors..here is the WORKING code


    Code:
    Dim imgCodecs() As ImageCodecInfo  = ImageCodecInfo.GetImageEncoders()
    	
    Dim params As EncoderParameters = New EncoderParameters(1)
    Dim quality As EncoderParameter = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 50)
    'Set quality to 50
    params.Param(0) = quality
    	
    newBitmap.Save("c:\blah.jpg", imgCodecs(1), params)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Kiweed
    Guest

    Thumbs up Thanks for the quick reply!

    I had a feeling it was one of the other more complicated options.

    In typical Microsoft fashion it can be done...if you know where to find it.

    Would be nice if they had a few functions like

    SaveAsJPG(name as string, quality as integer, descr as string, ...)

    Maybe I'll just create such a function myself

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    well it is just that the EncoderParameter covers more than just JPegs..it was written that way to cover a wider range of use...BTW here are the other Parameters you can set

    ChrominanceTable
    ColorDepth
    Compression
    LuminanceTable
    RenderMethod
    SaveFlag
    ScanMethod
    Transformation
    Version

    I may look into wrapping all this stuff into a dll to make it easier when i get the time.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

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



Click Here to Expand Forum to Full Width