2 Attachment(s)
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:
Attachment 194621
Notes
Requires the RC6 library.
Source Code:
Attachment 194646
(Includes demo image which accounts for most of the file size - source code is < 50kb)
Enjoy!
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 :)
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).
1 Attachment(s)
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:
Attachment 194647
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%.
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.....
Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class
Very useful tool, I'm happy with an RC6 version or plain GDI+.
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>
Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class
Quote:
Originally Posted by
SomeYguy
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.
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
1 Attachment(s)
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.
Attachment 194653
Re: cCropper: Simple, "Smart" RC6/Cairo Image Cropping Class
Quote:
Originally Posted by
jpbro
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 :).
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.