Platform: Windows Server 2016, Lazarus 2.0.10, FPC 3.2.0
Problem: I have many small images I want to remove the background from, so that I can paste them onto other larger images, and not have the original background show up. MS Paint is manual, I'd like to automate this. Plus the transparent copy refuses to work for me.
Condition: The background can be considered any color in the image that is the same as the color of the pixel in the top left corner.
Goal: I want to build a tiny Lazarus .exe that I can, in File Explorer, drag/drop a .jpg image file onto, and it will:
- Load the dropped image into some kind of control (I suspect TBGRAGraphicControl ?)
- Detect the color of the pixel in the top left corner
- Set all pixels in the image that match that color to transparent
- Save the image to a file with the same name, except with "_tbk.jpg" at the end. Example: ("rose.jpg" becomes "rose_tbk.jpg") "tbk" stands for "transparent background" [Note: this part might not be necessary, since I'm not sure if transparent pixels are saved to a file or if they are just set to white or black. If so, skip this step]
- Automatically copies the transparent image to the clipboard
- Closes itself
I cd then just paste the small image with a transparent background onto the larger image in the correct place.
Why am I doing this?
- MS Paint transparent copy function is not working (always includes the background)
- I'd like to automate this process, since I can always be sure the background color will be the same as the color of the pixel in the top left corner.
I have never used TBGRAGraphicControl before, and I'm not very familiar with image processing. I need help with:
- Loading the file
- Detecting the top left pixel color
- Scanning the image pixels and changing them to transparent
- Saving the file [if this step is necessary or useful]
- Copying the image (including the transparent pixels) to clipboard
Any help would be greatly appreciated. Thank you.
P.S. I'm looking at LazPaint, and it appears to be way overkill, plus like MS Paint, it's manual, plus I can't see how to do what I want to do. I'd rather have a tiny utility that does what I described above.