Page 1 of 2 12 LastLast
Results 1 to 40 of 44

Thread: [RESOLVED] how to reduce jpg filesize without reducing dimension

  1. #1

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Resolved [RESOLVED] how to reduce jpg filesize without reducing dimension

    Hello guys,

    Is there anyway to reduce jpg filesize ether by compression or color reduction to 256 color or Both.

    AM guessing GDI will be involved, but I don't know how to do this

    any ideas.
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  2. #2
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: how to reduce jpg filesize without reducing dimension

    What are you using now to create/save JPEG's?

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how to reduce jpg filesize without reducing dimension

    JPEG can't have 256 colors, unless it is a black'n'white JPEG. The file format does not use palettes. So that will not be a solution if you want a JPEG file. PNG is far superior for paletted and/or lossless images. The only advantage with GIF format over PNG is that it can produce smaller 1-bit images (ie. 2 colors only in the palette).

    Normally JPEG should compress pretty well. However digital cameras and such use, I guess, a lossless variant of JPEG which will result in a much bigger filesize – atleast the files are very huge when compared to normally saved 100% quality compressed JPEG.

    Anyway, giving the current code what you have for JPEGs will help a lot. If using an external DLL is a solution, then you may wish to have a look at vbAccelerator's article on JPG.


    My personal preference in quality for saving JPEG files is 93. For some reason higher settings sometimes result in an extra "line" appearing at the bottom edge of the picture, especially if it contains a lot of red. This seems to simply disappear when using quality 93. And this same seems to happen with both new & old software, so it may be an issue in JPEG encoding in general.
    Last edited by Merri; Aug 8th, 2010 at 10:35 AM.

  4. #4

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how to reduce jpg filesize without reducing dimension

    I also found a selfcontained JPEG parser class from PSC. It isn't fit for saving the files, but it is able to give detailed information of a JPEG file which can be used to find out reasons why a specific JPEG file is huge etc. (digital cameras also save a thumbnail into the JPEG file).

    There is also a CJPEGi class in PSC, which is a VB6 code only solution for compressing JPEG images. It probably could be optimized for speed a bit more, but being complex stuff it is unlikely to happen.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: how to reduce jpg filesize without reducing dimension

    You can also use Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting if you have an old version of Windows (i.e. XP).

    It is included in Vista and Windows 7.

    You can use this to do lots of things, including using its Convert filter to produce a JPEG saved with a given Quality level. It can also load and save PNG and TIFF formats in addition to GIF, BMP, and JPEG.

    It can be handy for PNGs in VB6, since it will load a PNG and expose it as a StdPicture object.


    It has filters for Rotate/Flip, Stamping, Scaling, Cropping, editing or reading Exif data, etc. and handles alpha transparency.

    I'm not sure why people seem so afraid of it. It's right there in Windows and specifically meant for use by VB6 programmers.

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how to reduce jpg filesize without reducing dimension

    dilettante: when it was released (in 2002) XP wasn't in as wide use as it is today. There were still tons of people using older versions of Windows. Today it is different, XP is often the minimum OS you can expect.

    Of course it is an extra file for installation process as well, but well, so is a JPEG DLL. Is making a silent installation for that component possible? In the other hand, even if it possible, not enough people know how to do that (execute a silent install during your application's main installation).

    It is a bit sad that some great dev tools released for VB6 didn't become widely used only because they required a too new version of Windows or because they came out a bit too late.

  8. #8
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    It is interesting that MartinLiss has mentioned FreeImage. FreeImage is indeed good stuff (albeit outstanding bugs) and I use it sparingly, e.g. to deal with multi-page TIFF, J2K/JP2 and camera raw formats, etc. It is extremely efficient in terms of speed. I tested it on 1, 2, 4, 8, 16, 24, 32, 48, 64-BPP PNGs alright (I don't use it for PNG as e.g. it can't save "interlaced"; I use my own stuff). When it comes to MNG, since it can only handle 1st frame of MNG (and yet can load limited types of it), I suggested to them to dispense with LibMNG.dll (subsequently on their request I submitted my example to demonstrate how it is feasible and yet can load more types of MNG than it currently can, be it PNG or JNG stream).

    In case anyone is interested, I can show you how to use VB wrapper pointed by MartinLiss to load JPG and save to GIF/PNG with FreeImage. Although FreeImage has active forums, unfortunately VB is hardly an item there.
    Last edited by petersen; Aug 8th, 2010 at 07:57 PM.

  9. #9
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: how to reduce jpg filesize without reducing dimension

    Hey Cool:

    I see you received lots of good suggestions for dealing with JPEG files. All this may be a bit of overkill if all you want to do is save & reduce the size of JPEG files.

    Attached is a short and, very sweet, basic module that gives you the ability to save a VB6 picture box to JPEG, PNG or BMP formats. This code was from Edgemeal a while back.

    Simply add the attached module to your project. Load your JPEG into a standard VB6 Picture box. Make sure you have the Picture box autosize set to True. To call the sub the syntax is:

    Code:
    SaveImageAs "c:\mypicture.jpg", Picture1.hdc, Picture1.Width / Screen.TwipsPerPixelX, Picture1.Height / Screen.TwipsPerPixelY, 75)
    The above code would save that image as mypicture.jpg to your c: drive with a JPEG Quality setting of 75. You can optionally change that setting.

    The key to file size with JPEG's is mainly through the setting of the quality setting. The settings range from 10 to 100. The higher the setting the better the quality of the image but the larger the file size. A setting of 50 can reduce the file size by as much as 75%... but the quality may or may not be acceptable. I don't think I would go less than 50. A lot depends on the native image. A reasonable compromise between image quality and file size is a JPEG quality setting of 75.

    Anyway... you can experiment and see what is acceptable to you.

    The good news is you don't need to download any dependency dll's, etc. to accomplish your stated goal of reducing JPEG filesize. And it comes with the ability to additionally save images as PNG.

    Have fun, Cool.

    Tom
    Attached Files Attached Files

  10. #10
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    coolcurrent4u,

    Tom Moran is right, if you are to save to JPG (but you are not). If your purpose is not to reduce file size, then you should just use the module he has kindly selected for you -- that would be the best solution for you [unless in a rare chance you are on Win ME, "as is" (a) you can't load when the image size is well over 300000 pixels and PictureBox AutoRedraw=True; and (b) you can't save even if the image size is small].

    Since your aim is to reduce file size, I am afraid the module wouldn't help. If you are to save to 8-BPP PNG, you have to convert your image to 8-BPP first, which you can't do with PictureBox. If you want to save to GIF by just calling the module, the resulting quality might not be okay (depending on the actual picture of yours, you can test-load your JPG to MS Paint and save it to GIF, the result would be about it. Often tens of thousands of colors would be reduced to only less than 100).
    Last edited by petersen; Aug 8th, 2010 at 07:44 PM.

  11. #11

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    TOM's
    The image source is not specific, mainly concerned about reducing filesize
    i'll check and see if the dimension is not reduced also

    Merri
    Thanks for the tips about jps generally, but vbAccelerator just metioned a dll used in loading jpegs, not compression, or did i get it wrong?

    MartinLiss
    FreeImage library would be an overkill for now as i just want to save in reduce filesize and same dimension. If i wanted to manipulate thje image, i'll use it.

    Petersen
    Must i use FreeImage library first to convert the image.

    dilettante
    Can you provide some sample code that use at leat most of the features of WIA
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  12. #12
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    Petersen
    Must i use FreeImage library first to convert the image.
    Please see the revised text in my earlier posting (for a moment I forgot your aim was to reduce the file size -- I thought you were to save to JPG).

    It is not a must for you to use FreeImage, it is just an option. But, MartinLiss mentioned it not without a reason. To optimize the JPG colors to 8-BPP (in an attempt to reduce the file size), you need to know the processes, therefore I guess MartinLiss didn't want to complicate the matter for you.
    Last edited by petersen; Aug 8th, 2010 at 07:45 PM.

  13. #13
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: how to reduce jpg filesize without reducing dimension

    It's not such a great idea to re-save a JPEG as JPEG, as there will be compounded degradation due to the lossy compression used. A better format would be PNG, as it uses lossless compression.

  14. #14
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: how to reduce jpg filesize without reducing dimension

    Hey Cool:

    Did you try the SaveAsImage routine I sent you? It does not affect the dimensions of the image, only the compression/quality level.

    FireXtol is correct about repeated savings of a JPEG. Sometimes, however, it doesn't matter, depending on what you are using the JPEG for and how the original was created. If the JPEG is largely for viewing on a typical computer monitor, the lossy degradation is barely perceptible to the user.

    Tom

  15. #15

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by Tom Moran View Post
    Hey Cool:

    I see you received lots of good suggestions for dealing with JPEG files. All this may be a bit of overkill if all you want to do is save & reduce the size of JPEG files.

    Attached is a short and, very sweet, basic module that gives you the ability to save a VB6 picture box to JPEG, PNG or BMP formats. This code was from Edgemeal a while back.

    Simply add the attached module to your project. Load your JPEG into a standard VB6 Picture box. Make sure you have the Picture box autosize set to True. To call the sub the syntax is:

    Code:
    SaveImageAs "c:\mypicture.jpg", Picture1.hdc, Picture1.Width / Screen.TwipsPerPixelX, Picture1.Height / Screen.TwipsPerPixelY, 75)
    The above code would save that image as mypicture.jpg to your c: drive with a JPEG Quality setting of 75. You can optionally change that setting.

    The key to file size with JPEG's is mainly through the setting of the quality setting. The settings range from 10 to 100. The higher the setting the better the quality of the image but the larger the file size. A setting of 50 can reduce the file size by as much as 75%... but the quality may or may not be acceptable. I don't think I would go less than 50. A lot depends on the native image. A reasonable compromise between image quality and file size is a JPEG quality setting of 75.

    Anyway... you can experiment and see what is acceptable to you.

    The good news is you don't need to download any dependency dll's, etc. to accomplish your stated goal of reducing JPEG filesize. And it comes with the ability to additionally save images as PNG.

    Have fun, Cool.

    Tom
    I did some loading and saving, but encountered a minor but important error

    on loading the picture to picture box, i then used the method you described to save the picture, but got the picture below.

    The extra spaces is added that is no needed, so i tried to resize the picture box to the size of the picture using this

    Code:
    Picture1.Width = Picture1.Picture.Width
    'debug.print shows this
    debug.print  Picture1.Width, Picture1.Picture.Width
    
    '9990          13414
    how do i do the conversion
    Attached Images Attached Images  
    Last edited by coolcurrent4u; Aug 9th, 2010 at 01:48 AM.
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  16. #16
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: how to reduce jpg filesize without reducing dimension

    You want images of the screen? PNG would probably be better. It also supports palettes, so you can really squeeze the file size.

    I just took a screenshot(of this page), and PNG 8 bit is 63 kB, PNG 24 bit is 157 kB, JPEG "high"(60%, optimized, progressive) is 178 kB. In order for JPEG to hit the size of the 8 bit PNG zero quality and blurring is required(see attachment for example). GIF(8 bit) is 98 kB. 8 bit PNG is the clear quality/size winner.
    Attached Images Attached Images  

  17. #17

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    Thank you FireXtol

    But for this project am doing, i need jpg only

    Do you know how to resize picturebox to the size of the image in it?
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  18. #18
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by coolcurrent4u View Post
    Thank you FireXtol

    But for this project am doing, i need jpg only

    Do you know how to resize picturebox to the size of the image in it?
    Set the AutoSize property to True.

  19. #19

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    AM getting an error.
    The picture is saved, but with extra regions around the picturebox

    please see the attached project.

    EDIT: I have reattached the project and included the missing files
    Attached Files Attached Files
    Last edited by coolcurrent4u; Aug 9th, 2010 at 07:25 PM.
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  20. #20
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how to reduce jpg filesize without reducing dimension

    Just a generic FYI, the original screenshot in the sample happens to be by me, here is the original PNG:



    The size is 12.31 kB while the JPG made out of it is 27.47 kB – although it does have some extra area around it, but if that extra area was in the PNG it would be compressed by a very high ratio being a single color. Edit! I re-saved the PNG image as-is using a 93% quality for JPEG and the size is 37.4 kB – and JPEG is not perfect quality unlike the PNG.

    But what I do wonder is FireXtol's attached JPEG, because it is over 50 kB and it looks like very bad quality! Was it saved in bad quality first and then at 100% quality?


    Anyway, PNG is superior over JPG when it comes to screenshots of most websites, GUIs & other non-photolike content And the small filesize for the image above was achieved using PngOptimizer.
    Last edited by Merri; Aug 9th, 2010 at 08:32 AM.

  21. #21
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: how to reduce jpg filesize without reducing dimension

    It's a PNG. I took a screenshot(1680x1050) and saved it at various settings(JPEG). The PNG is a cropped section of the screenshot(as even a 100% quality JPEG is lossy; I prefer lossless formats).

  22. #22
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to reduce jpg filesize without reducing dimension

    So the consensus from what I gather is there isn't much one can do with a JPG other than possibly saving the screenshot to a grayscale/256 color bitmap and seeing if that will be smaller; appears it will be slightly.

    Here's some examples of a 1920x1200 screenshot
    1. JPG full color: 355k (80% quality using GDI+)
    2. JPG grayscale: 288k (80% quality using GDI+)
    3. PNG full color (using GDI+): 1.7mb
    4. GIF: 289k

    Note about #3. GDI+ PNG compression uses only 1 algorithm & a couple bit-depths, I believe. There are 5 or 6 algorithms that PNG supports & several bit-depth formats but requires either 3rd party DLLs to use them or manually processing/writing pixels to PNG format.
    Last edited by LaVolpe; Aug 9th, 2010 at 09:27 AM. Reason: typo
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  23. #23
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by petersen View Post
    It is interesting that MartinLiss has mentioned FreeImage. FreeImage is indeed good stuff (albeit outstanding bugs) and I use it sparingly, e.g. to deal with multi-page TIFF, J2K/JP2 and camera raw formats, etc. It is extremely efficient in terms of speed. I tested it on 1, 2, 4, 8, 16, 24, 32, 48, 64-BPP PNGs alright (I don't use it for PNG as e.g. it can't save "interlaced"; I use my own stuff). When it comes to MNG, since it can only handle 1st frame of MNG (and yet can load limited types of it), I suggested to them to dispense with LibMNG.dll (subsequently on their request I submitted my example to demonstrate how it is feasible and yet can load more types of MNG than it currently can, be it PNG or JNG stream).

    In case anyone is interested, I can show you how to use VB wrapper pointed by MartinLiss to load JPG and save to GIF/PNG with FreeImage. Although FreeImage has active forums, unfortunately VB is hardly an item there.
    You can also see how it can be used in my Picture/video Viewer.

  24. #24
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    To MartinLiss:

    Thank you. I've fetched your v1.7.zip. From the outset, I can see that you had made a rather extensive use of FreeImage and your last update being in Feb this year is quite current. I surely will have a good look at it.


    To general:

    Each file format has its own merits and demerits. It is like C++ and NET/C guys shouldn't just say VB is no good.

    For your info, even professional radiology associations approved (the year before?) their members (radiologists) to archive their images in JPG despite its "lossy" status. Radiologists have DICOM format, but they also use images in JPG on daily basis (and they prefer grayscale over color; color ones are there to facilitate others who are not of their own discipline). An "80% quality" (like the one exemplified by La Volpe above), or a "75% quality", is fine with them (because it is the "make sense" one).

    And don't look down on GIF either. After more than 10 years it is still very much alive, but MNG which was once an all singing and all dancing marvel is basically dead, and I don't believe the animated PNG would ever really take off the ground either.

    PNG is excellent and I like it naturally. But let us cool down a bit for a moment, (a) those beautiful 32-BPP pictures are made by somebody else, how many of us have actually produced such a one ourselves (involving editing alpha channel values)? (b) What about the file size of a beautiful 32-BPP PNG. if we somehow need to convert a 32-BPP PNG to 8-BPP, would the resultant image be really okay?
    Last edited by petersen; Aug 9th, 2010 at 01:40 PM.

  25. #25

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    Wow so much information about images/pictures. Png is definately better. But I need jpg for several reasons best know to me.

    You guys sound as if jpg is going close to its grave!

    please did anybody help me look at the attached project and found any error(s)?

    Well for the freeimage library, i don't know if i can include it in a commercial app. If i devote time to using its function and later can't use it in a commercial app, it is then of no need or what do you guys think?
    Last edited by coolcurrent4u; Aug 9th, 2010 at 01:48 PM. Reason: typo
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  26. #26
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how to reduce jpg filesize without reducing dimension

    Nah, you forget JPG is still the ideal format for photos and other images that do not need to be pixel perfect.

    (However, mostly because none of the great lossy formats that do exist is free. There is JPEG2000 for example that gives a lot better quality/compression ratio, but you need to pay a license to use it. Edit! Or Wikipedia states it should be license free. Hmmh, seems like there is "bad" information regarding it over the Internet. Also, the sample image doesn't give as good result as I'd have expected. Edit #2! Better comparisons)
    Last edited by Merri; Aug 9th, 2010 at 02:10 PM.

  27. #27
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to reduce jpg filesize without reducing dimension

    There are other ways of creating JPGs without using FreeImage: Manually as Merri posted in #5 above, WIA? mentioned in #6 and GDI+. There's also an Intel DLL floating around on the web referenced in vbAccelerator's project (post #3 above). So you have plenty of options I would think. I doubt JPG is anywhere near death.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  28. #28

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by LaVolpe View Post
    There are other ways of creating JPGs without using FreeImage: Manually as Merri posted in #5 above, WIA? mentioned in #6 and GDI+. There's also an Intel DLL floating around on the web referenced in vbAccelerator's project (post #3 above). So you have plenty of options I would think. I doubt JPG is anywhere near death.
    Yes there are many options, but the main feature is that i need to be able to adjust the saving quality, like in Merris post.

    The reason for this is so that i can adjust the size of a jpg and save to get a smaller filesize

    I compiled a test project and am getting errors

    The file i attached in the second to the last post

    can you help me look at it?
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  29. #29
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by coolcurrent4u View Post
    Yes there are many options, but the main feature is that i need to be able to adjust the saving quality, like in Merris post...
    I don't know about WIA (not familiar with it), but all the other options mentioned: JPG class on PSC, GDI+, Intel DLL, FreeImage (if I recall) do allow a user-defined quality setting.

    P.S. Haven't looked at your file.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  30. #30
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: how to reduce jpg filesize without reducing dimension

    Hey Cool:

    I tried to load your file but it has references to class modules I don't have in directories not on my computer... so I can't test it. You also did not include the Module containing the save as jpeg.... but I do have that.

    Here are a couple of things for you to check:

    Make sure your picture box has autoredraw and and autosize set to True. After you load the picture in the picture box but before you call the saveas sub also add this line:

    Picture1.Picture = Picture1.Image

    If that doesn't work for you I'll send you a small project which shows you a successful implementation of the sub.

    And, BTW, JPEG, with all it's lossy shortcomings and 24bit limitations, is still the most popular image format around.

  31. #31
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    Merri,

    Just for info. There are different JPEG2000 libraries made by different people. Because it is so technically difficult to make one, the quality disparity between them is huge in their Save functions. For example, the one used by FreeImage is much inferior than that by IrfanView. As a result, there are JPEG2000 files of different qualities around.

    Unlike JPEG, a real good JPEG2000 does not have the usual artifacts, and it can have 32-BPP and 8-BPP images as well.

    JPEG2000 has failed to gain popularity over the years.

    Wikipedia had not given bad info; it is just situations do vary, e.g. I mentioned that the one used by IrfanView was superior, however you have to pay if you want to save files of image over a certain size (I forgot the size and how, it was quite a while ago).
    Last edited by petersen; Aug 9th, 2010 at 03:11 PM.

  32. #32
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how to reduce jpg filesize without reducing dimension

    Nah, I didn't mean Wikipedia's bad info: I meant earlier mentions I've read elsewhere over the years. Wikipedia states somewhat the same, confusing information floating around on JPEG2000. I also remember having some license window popping up when I tried saving JPEG2000 a few years ago, so that kept me away of it.

    I did some more research and I also found out about JPEG XR which originates from Microsoft. It claims to be simpler than JPEG 2000 and also gives some unique features (partial cropped decoding of image, lower quality decode of the full image, simple effects such as rotations on the fly...)

    But meh, unusable due to lack of popularity & support. JPEG2000 is available in graphics programs, but lack of support in the web browser field is a bit sad. In future IE9 adds support for JPEG XR... but graphics tools seem to lack support pretty bad. Creators of libjpeg seem to be against JPEG XR so it looks like it won't have a sudden rise in popularity anytime soon. The quality & filesize advances over JPEG would be great though in both JPEG2000 and JPEG XR after seeing a few comparisons.

  33. #33
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: how to reduce jpg filesize without reducing dimension

    Using WIA 2.0 to transcode from another format or a 100% quality JPEG to a lower-quality JPEG is pretty simple:
    Code:
    Option Explicit
    '
    'Requires a reference to:
    '   Microsoft Windows Image Acquisition Library v2.0
    '
    
    Public Sub ConvertJpegQuality( _
        ByVal InFileName As String, _
        ByVal OutFileName As String, _
        ByVal Quality As Integer)
        
        Dim Img As WIA.ImageFile
        Dim ImgProc As WIA.ImageProcess
        
        If 1 <= Quality And Quality <= 100 Then
            Set Img = New WIA.ImageFile
            Img.LoadFile InFileName
            Set ImgProc = New WIA.ImageProcess
            With ImgProc.Filters
                .Add ImgProc.FilterInfos("Convert").FilterID
                .Item(1).Properties("FormatID").Value = wiaFormatJPEG
                .Item(1).Properties("Quality").Value = Quality
            End With
            Set Img = ImgProc.Apply(Img)
            
            On Error Resume Next
            Kill OutFileName
            On Error GoTo 0
            Img.SaveFile OutFileName
        Else
            Err.Raise 5 'Invalid procedure call or argument.
        End If
    End Sub
    
    Private Sub Main()
        ConvertJpegQuality "sample100.jpg", "sample10.jpg", 10
        ConvertJpegQuality "sample100.jpg", "sample50.jpg", 50
        ConvertJpegQuality "sample100.jpg", "sample90.jpg", 90
        MsgBox "Complete"
    End Sub
    Last edited by dilettante; Oct 20th, 2022 at 01:41 PM.

  34. #34
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    dilettante,

    Your example project is great! Solid and convincing.

    I think by now coolcurrent4u should have been convinced by you, and Tom Moran, that is kind of approach is the best for him to pursue (unless he sees a problem concerning distribution, I myseld do not).
    Last edited by petersen; Aug 9th, 2010 at 05:40 PM.

  35. #35
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by Merri View Post
    Is making a silent installation for that component possible? In the other hand, even if it possible, not enough people know how to do that (execute a silent install during your application's main installation).
    There is just one file from the WIA 2.0 SDK you need to distribute: wiaaut.dll


    As always, you are not supposed to package applications for deployment using DLLs or OCXs from your "live" system anyway (e.g. System32). This is why the PDW has its Redist folder and why we have merge modules for use with Installer-compatible packagers.

    To deploy using the PDW you can simply copy the wiaaut.dll from the downloadable SDK into the PDW's Redist folder, typically:
    C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Redist
    If the resulting setup package is run under Vista or later the "old XP version" will be skipped/ignored when the newer system version is detected.


    You can also add the same SDK DLL into any XCopy deployment package for your application, presuming you're using a Reg-Free COM isolation manifest. On Vista or later systems this will be ignored and the system copy will be used, while XP systems will use the isolated copy you supplied from the SDK.


    I just tested all 3 scenarios to make sure:
    • PDW setup package with wiaaut.dll from the WIA 2.0 SDK, setup run on a clean XP SP3 machine.
    • XCopy isolated application folder with wiaaut.dll from the WIA 2.0 SDK, copied to a clean XP SP3 machine.
    • XCopy isolated application folder with wiaaut.dll from the WIA 2.0 SDK, copied to a clean Vista SP2 machine.

    Worked fine in all cases.

  36. #36
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by petersen View Post
    dilettante,

    Your example project is great! Solid and convincing.
    Even nicer this runs at "full speed" from a WSH or MSHTA script (VBScript) or in VBA.

    I know we have VBA fans here.

  37. #37
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    dilettante,

    I also concur regarding P&W. No problem on DLL items. I use VB P&W (modified quite bit, e.g. beautify a bit and streamline the size of two main forms, allow choices for desktop icon and provide multi-submenus in system programs menu listing). WinZip Self-Extract is used for the installation EXE (old one still, as I don't see much diff for the newer one except the new one would result in a slightly bigger file size).

    The only problem I ever encountered was years ago when Vista first came out. It was concerning itircl.dll. But this was only due to an old problem of Error HHC6003of Windows bug re-surface on registering HTML Help drivers. That prompted me to might as well dispense with the supply of HTML Help related DLLs (i.e. I was benifited by that Windows bug in reducing the installation file size). Just a side story.

  38. #38

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by Tom Moran View Post
    Hey Cool:

    I tried to load your file but it has references to class modules I don't have in directories not on my computer... so I can't test it. You also did not include the Module containing the save as jpeg.... but I do have that.

    Here are a couple of things for you to check:

    Make sure your picture box has autoredraw and and autosize set to True. After you load the picture in the picture box but before you call the saveas sub also add this line:

    Picture1.Picture = Picture1.Image

    If that doesn't work for you I'll send you a small project which shows you a successful implementation of the sub.

    And, BTW, JPEG, with all it's lossy shortcomings and 24bit limitations, is still the most popular image format around.
    Hello TOM,

    I have reattached the project and included the missing files as you requested.
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  39. #39

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: how to reduce jpg filesize without reducing dimension

    Quote Originally Posted by dilettante View Post
    Using WIA 2.0 to transcode from another format or a 100% quality JPEG to a lower-quality JPEG is pretty simple:
    Code:
    Option Explicit
    '
    'Requires a reference to:
    '   Microsoft Windows Image Acquisition Library v2.0
    '
    
    Public Sub ConvertJpegQuality( _
        ByVal InFileName As String, _
        ByVal OutFileName As String, _
        ByVal Quality As Integer)
        
        Dim Img As WIA.ImageFile
        Dim ImgProc As WIA.ImageProcess
        
        If 1 <= Quality And Quality <= 100 Then
            Set Img = New WIA.ImageFile
            Img.LoadFile InFileName
            Set ImgProc = New WIA.ImageProcess
            With ImgProc.Filters
                .Add ImgProc.FilterInfos("Convert").FilterID
                .Item(1).Properties("FormatID").Value = wiaFormatJPEG
                .Item(1).Properties("Quality").Value = Quality
            End With
            Set Img = ImgProc.Apply(Img)
            
            On Error Resume Next
            Kill OutFileName
            On Error GoTo 0
            Img.SaveFile OutFileName
        Else
            Err.Raise 5 'Invalid procedure call or argument.
        End If
    End Sub
    
    Private Sub Main()
        ConvertJpegQuality "sample100.jpg", "sample10.jpg", 10
        ConvertJpegQuality "sample100.jpg", "sample50.jpg", 50
        ConvertJpegQuality "sample100.jpg", "sample90.jpg", 90
        MsgBox "Complete"
    End Sub
    The attachment is large because it contains an 82KB sample 100% JPEG image.
    Thank you, this is certainly what am looking for except that there is still a catch.

    The wia dll is >300KB, thats much for a small project. But honestly, I'd prefer the GDI stuff.

    I'll use the in another project because of its simplicity
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  40. #40
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: how to reduce jpg filesize without reducing dimension

    codecurrent4u,

    Before I disappear I made a last round of tour and saw your above postings. I thought I might as well make a quick run of it.

    Would you please do the following:

    (1) All files you used are in zip. However when I invoked the project, only the Form was loaded. I have to add BAS and CLSs back to your project. Please re-check on this point.

    (2) You forgot to set PictureBox AutoRedraw to True.

    That is it from me. If you don't replace your attachment yet, I believe Tom Moran would verify what I said for you, and give you further help if needed.
    Last edited by petersen; Aug 9th, 2010 at 09:44 PM. Reason: Removed "3"

Page 1 of 2 12 LastLast

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