Results 1 to 12 of 12

Thread: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,897

    cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    cCropper is a small and fast VB6/RC6 class designed to make image cropping easy, and to allow you to add image cropping to your VB applications (nearly) effortlessly.

    In addition to being a useful stand-alone class, the code has also been thoroughly commented, making it useful as learning material for RC6/Cairo graphics features and functionality.

    Features:

    • UI Mode:
      Let users visually select, move, and resize crop areas with the mouse.

    • Programmatic Mode:
      Define crop rectangles and process images entirely through code.

    • Format Support:
      Load and save PNG, JPEG, and BMP files.

    • "Smart" File Size Control:
      Automatically resize files to stay near a target maximum byte size - perfect for uploads and email attachments.

    • Image Size Control
      Define the maximum pixel width/height for your cropped image - useful for generating thumbnails.



    Screenshot:

    Name:  2025-04-20_13-06-57.jpg
Views: 1650
Size:  31.2 KB


    Notes

    Requires the RC6 library.


    Source Code:

    RC6CairoImageCropper4.zip

    (Includes demo image which accounts for most of the file size - source code is < 50kb)


    Enjoy!
    Last edited by jpbro; Apr 24th, 2025 at 03:57 PM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,897

    Re: cCropper: Simple, Smart RC6/Cairo Image Cropping Class

    Quick note about the "Smart" File Size Control feature - it's fairly experimental, so please let me know if you get any surprising results (ideally providing an image and export format for testing). Thanks

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,897

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    Added the ability to set a maximum Pixel size for the image. Useful for generating thumbnails (image will be centred horizontally and vertically if it doesn't fit the max pixel width/height squarely).

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,897

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    Added a "SharpenOnShrink" Boolean parameter to the SaveImage method. When shrinking images, they can look a bit blurry, and Sharpening them can produce more pleasing/pseudo-detailed results:

    Name:  2025-04-24_16-54-19.jpg
Views: 1284
Size:  48.0 KB

    My approach will do a single-pass Sharpen if the scaled image size is <67% of the original image size, and double-pass Sharpen if < 33%.

  5. #5
    Hyperactive Member
    Join Date
    Feb 2015
    Posts
    324

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    Thank you, this is wonderful . For my purposes I will likely rewrite using GDI+. Nothing against RC6 but don't want the extra dependencies because my use case is inside a custom control. And I think that Cairo uses GDI & GDI+ as backends on Windows anyway.....

  6. #6
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,560

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    Very useful tool, I'm happy with an RC6 version or plain GDI+.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,192

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    > And I think that Cairo uses GDI & GDI+ as backends on Windows anyway.....

    No, it does not. This would be very backwords logic and ChatGPT confirms: https://chatgpt.com/share/680f402b-9...9-2f83699721b3

    cheers,
    </wqw>

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,897

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    Quote Originally Posted by SomeYguy View Post
    Thank you, this is wonderful . For my purposes I will likely rewrite using GDI+.
    Glad you like it, and looking forward to your GDI+ version if you should decide to share it. Be interesting to compare LoC and # hours it takes to implement in GDI+ vs. RC6/Cairo.

  9. #9
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,560

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    No, RichClient 6 Cairo wrapper does not use GDI+.

    Here’s a breakdown:

    RichClient 6 (RC6) is a COM-based framework developed by Olaf Schmidt for VB6 and other COM-capable environments.

    The Cairo wrapper in RC6 is a direct binding to the Cairo graphics library (a C library).

    Cairo is a powerful, hardware-accelerated 2D graphics library that renders directly using backends like Win32, Direct2D, OpenGL, Skia, and others — but it does not rely on GDI+.

    RC6 accesses Cairo.dll (and some helper DLLs) directly through lightweight COM classes.

    In fact, Olaf deliberately avoided GDI+ because GDI+ is slower, more limited, and less accurate (especially with alpha-blending and transforms) compared to Cairo.

    Straight from ChatGPT
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  10. #10
    Hyperactive Member
    Join Date
    Feb 2015
    Posts
    324

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    wqweto: Meant to quote your reply but forgot to reply w/quote. Anyway - Looks like the AIs don't agree with each other on this but I tend to believe ChatGPT so I'm sure you're right. I agree with you that it would be backward logic for Cairo but GDI/GDI+ are still great options in many cases and the .NET framework simply wraps GDI+ for its 2D graphics capability.

    Regarding RC6, it truly is wonderful and a fantastic achievement and tool by Olaf and I do use it for some things. But for certain applications I just can't redistribute several base dlls and/or use manifests for reg-free running.

    Name:  cairogdi.jpg
Views: 1280
Size:  65.4 KB
    Last edited by SomeYguy; Apr 28th, 2025 at 12:19 PM.

  11. #11
    Hyperactive Member
    Join Date
    Feb 2015
    Posts
    324

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    Quote Originally Posted by jpbro View Post
    Glad you like it, and looking forward to your GDI+ version if you should decide to share it. Be interesting to compare LoC and # hours it takes to implement in GDI+ vs. RC6/Cairo.
    Most certainly I will be happy to share whenever I get it finished .

  12. #12
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,560

    Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class

    You cannot trust AI to give you an accurate answer, it is just as likely to give you hearsay. I was recently investigating a method of reading an icon from a HIcon via a bitstream and it invented two very plausible APIs that would have done the trick perfectly, if only they had ever existed.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

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