### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Make a Transparent Image: Iterate over pixels & replace colors within tolerance  (Read 524 times)

#### Boleeman

• Hero Member
• Posts: 641
##### Make a Transparent Image: Iterate over pixels & replace colors within tolerance
« on: August 30, 2024, 08:06:21 am »
Made a utility program to make a transparent image or just load an image and make an Icon

Uses Bgrabmp.

You can select a point or choose the (0,0) default.

It Iterates over each pixel and replace colors within a certain tolerance

Just realized that the zip file was missing the unit1.pas source so I re-uploaded.
« Last Edit: August 30, 2024, 09:57:05 am by Boleeman »

#### d2010

• New Member
• Posts: 46
##### Re: Make a Transparent Image
« Reply #1 on: August 30, 2024, 09:07:51 am »
I known two methods
Code: [Select]
`    if (ob.text<>obTransparent)  then        ob.Color := Color.FromArgb(0,c.R,c.G,c.B)      else ob.Color := Color.FromArgb(255,c.R,c.G,c.B);`

#### Boleeman

• Hero Member
• Posts: 641
##### Re: Make a Transparent Image: Iterate over pixels & replace colors within tolerance
« Reply #2 on: August 30, 2024, 10:00:06 am »

My version Iterates over each pixel and replace colors within a certain tolerance.

A little update: Make a Semi-Transparent Background
« Last Edit: August 30, 2024, 10:25:13 am by Boleeman »

#### Boleeman

• Hero Member
• Posts: 641
##### Re: Make a Transparent Image: Iterate over pixels & replace colors within tolerance
« Reply #3 on: August 30, 2024, 10:51:42 am »
When working with jpg, the selected point color is not always consistent so...

I set up a Color Tolerance Level TSpinedit

The higher the tolerance the more variation of the selected point color.
The lower the tolerance the less variation there is of the selected point color.

As seen in the attached png, the loaded jpg is not quite white at the roof edges so that is when to use the TSpinedit Color Tolerance.

Also attached: A few of my square fractals with the backgrounds made transparent.
« Last Edit: August 30, 2024, 11:13:21 am by Boleeman »