Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
»
BGRABitmap and LazPaint
»
Convert BGRAbitmap to 256 Color BMP and save
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
I hope FreePascal can sup...
by
xiyi0616
[
Today
at 05:49:05 am]
Ann: DeCoperators
by
Fibonacci
[
Today
at 03:59:13 am]
[Solved] Help needed comp...
by
landolfi
[
Today
at 02:45:10 am]
Delimited text - how find...
by
Remy Lebeau
[
Today
at 02:26:15 am]
AI assisted translation o...
by
MathMan
[
Today
at 12:55:30 am]
DataPort or Synpase stat...
by
eldonfsr
[April 16, 2026, 11:32:18 pm]
Ann: Deinline: a de-inlin...
by
LeP
[April 16, 2026, 11:27:18 pm]
[FPC 3.2.4, Windows] PTC ...
by
Fred vS
[April 16, 2026, 08:26:24 pm]
Cannot build Units for Si...
by
NormanDunbar
[April 16, 2026, 07:39:07 pm]
IDE: Property editor does...
by
dsiders
[April 16, 2026, 07:04:22 pm]
What is wrong with this c...
by
OH1KH
[April 16, 2026, 04:32:48 pm]
FPC Unleashed (inline var...
by
LeP
[April 16, 2026, 04:22:24 pm]
[work arounded]Naming dae...
by
LeP
[April 16, 2026, 03:36:10 pm]
Lazarus Bugfix Release 4....
by
Jonax
[April 16, 2026, 03:06:25 pm]
Error: Compilation raised...
by
janasoft
[April 16, 2026, 02:29:19 pm]
CudaText editor (written ...
by
AlexTP
[April 16, 2026, 10:43:12 am]
C header function with on...
by
440bx
[April 16, 2026, 09:13:38 am]
(Solved)TUpDown KeyDown ...
by
LeP
[April 15, 2026, 11:21:09 pm]
Zipper: Addition of mult...
by
marcov
[April 15, 2026, 10:35:15 pm]
Seeking advice on setting...
by
gidesa
[April 15, 2026, 07:02:04 pm]
GTK3: FillRect() mispaint...
by
baldzhang
[April 15, 2026, 06:32:52 pm]
Lazarus Image Editor
by
Paolo
[April 15, 2026, 05:37:30 pm]
RunFormula: math expressi...
by
Handoko
[April 15, 2026, 01:24:30 pm]
How to merge multiple cla...
by
cdbc
[April 15, 2026, 12:48:42 pm]
PWM signals, atmega328p, ...
by
pascalbythree
[April 15, 2026, 12:39:25 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Convert BGRAbitmap to 256 Color BMP and save (Read 1276 times)
winni
Hero Member
Posts: 3197
Convert BGRAbitmap to 256 Color BMP and save
«
on:
November 17, 2022, 02:08:35 pm »
Hi!
Question in the german forum:
How to convert BGRAbitmap to a 256 Color BMP and save it?
It is needed by some SAP software that rejects all images except 256-Color-BMP.
Is there a solution yet? I have not found anything.
Winni
Logged
paweld
Hero Member
Posts: 1598
Re: Convert BGRAbitmap to 256 Color BMP and save
«
Reply #1 on:
November 17, 2022, 05:13:52 pm »
Hi,
sample code:
Code: Pascal
[Select]
[+]
[-]
uses
BGRABitmap
,
BGRABitmapTypes
,
BGRAColorQuantization
,
FPWriteBmp
;
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
var
img
:
TBGRABitmap
;
bmpw
:
TFPWriterBmp
;
quant
:
TBGRAColorQuantizer
;
i
:
Integer
;
begin
img
:
=
TBGRABitmap
.
Create
(
'd:\wzor80.jpg'
)
;
bmpw
:
=
TFPWriterBmp
.
Create
;
bmpw
.
BitsPerPixel
:
=
8
;
//bmpw.RLECompress := True;
quant
:
=
TBGRAColorQuantizer
.
Create
(
img
,
acIgnore
,
256
)
;
//reduce color to 256 without alfa
quant
.
ApplyDitheringInplace
(
daNearestNeighbor
,
img
)
;
img
.
UsePalette
:
=
True
;
img
.
Palette
.
Clear
;
for
i
:
=
0
to
quant
.
ReducedPalette
.
Count
-
1
do
//copy reduced colors to palette
img
.
Palette
.
Add
(
quant
.
ReducedPalette
.
Color
[
i
]
.
ToFPColor
)
;
img
.
SaveToFile
(
'd:\wzor80_256color.bmp'
,
bmpw
)
;
//save as bmp
bmpw
.
Free
;
//clean
img
.
Free
;
quant
.
Free
;
end
;
Logged
Best regards / Pozdrawiam
paweld
winni
Hero Member
Posts: 3197
Re: Convert BGRAbitmap to 256 Color BMP and save
«
Reply #2 on:
November 17, 2022, 05:37:06 pm »
Hi!
Thanx a lot.
The Quantizer was the part that I forgot. Getting old ...
The Link in the german forum:
https://www.lazarusforum.de/viewtopic.php?f=18&t=14593&p=131460#p131460
Winni
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
»
BGRABitmap and LazPaint
»
Convert BGRAbitmap to 256 Color BMP and save
TinyPortal
© 2005-2018