Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
(Moderator:
Ask
) »
merge two images
Free Pascal
Website
Downloads
Wiki
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Bugtracker
IRC channel
Latest SVN
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
BGRAsvg: Image to big
by
circular
[
Today
at 08:17:07 am]
How to assign default eve...
by
jamie
[
Today
at 04:31:45 am]
Help Needed
by
gcarreno
[
Today
at 03:50:11 am]
Translated Textbook
by
norm
[
Today
at 12:57:20 am]
case of
by
winni
[
Today
at 12:32:34 am]
converting C++ over laz, ...
by
korba812
[
Today
at 12:19:54 am]
[SOLVED] Is this a bug in...
by
Bart
[March 06, 2021, 11:15:36 pm]
What's wrong with my code...
by
justnewbie
[March 06, 2021, 10:34:58 pm]
STM32 interrupts
by
MiR
[March 06, 2021, 09:30:41 pm]
Zeos/MariaDB: Instead of ...
by
af0815
[March 06, 2021, 09:20:03 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: merge two images (Read 4632 times)
klausbits
New Member
Posts: 29
merge two images
«
on:
July 07, 2016, 11:00:00 am »
Hi.
I want to interpolate between two images like this
Code: Pascal
[Select]
[+]
[-]
var
picture1
,
picture2
,
picture3
:
Tpicture
;
picture1
:
=
Tpicture
.
create
;
picture2
:
=
Tpicture
.
create
;
picture3
:
=
Tpicture
.
create
;
picture1
.
LoadFromFile
(
d
:
\image1
.
jpg
)
;
picture2
.
LoadFromFile
(
d
:
\image2
.
jpg
)
;
picture3
=
0.7
*
picture1
+
0.3
*
picture2
;
how can I do this?
Logged
Thaddy
Hero Member
Posts: 10707
Re: merge two images
«
Reply #1 on:
July 07, 2016, 11:06:05 am »
You need to set transparency levels for those pictures so the one shines through the other.
Logged
klausbits
New Member
Posts: 29
Re: merge two images
«
Reply #2 on:
July 07, 2016, 11:26:56 am »
to Thaddy,
thanks for the tip. I have to think about this if it serves my purpose.
Rather I thought to have
red3:=0.7*red1+0.3*red2;
green3:=...
blue3:=...
Logged
Thaddy
Hero Member
Posts: 10707
Re: merge two images
«
Reply #3 on:
July 07, 2016, 11:35:39 am »
@Klausbits:
Yup,
that is basically what transparency does
<very big smile> so why re-invent wheels? I never got further than an octagonal one....
You got the algorithm almost spot on but think about weights of the values. Now let your drivers do the real work
«
Last Edit: July 07, 2016, 11:41:23 am by Thaddy
»
Logged
klausbits
New Member
Posts: 29
Re: merge two images
«
Reply #4 on:
July 07, 2016, 11:55:12 am »
to Thaddy,
I am not sure thsat this is the same (pardon me, I am a physicist;-)
How would you program your proposal?
Logged
circular
Hero Member
Posts: 3668
Re: merge two images
«
Reply #5 on:
July 07, 2016, 03:11:28 pm »
How to do that with BGRABitmap:
Code: Pascal
[Select]
[+]
[-]
uses
BGRABitmap
,
BGRABitmapTypes
;
var
bmp1
,
bmp2
,
bmp3
:
TBGRABitmap
;
begin
bmp1
:
=
TBGRABitmap
.
Create
(
'd:\image1.jpg'
)
;
bmp2
:
=
TBGRABitmap
.
Create
(
'd:\image2.jpg'
)
;
bmp3
:
=
TBGRABitmap
.
Create
(
bmp1
.
Width
,
bmp1
.
Height
)
;
//note that size may be different between bmp1 and bmp2
bmp3
.
CrossFade
(
Rect
(
0
,
0
,
bmp3
.
Width
,
bmp3
.
Height
)
,
bmp1
,
bmp2
,
round
(
0.3
*
255
)
,
dmSet
)
;
bmp1
.
Free
;
bmp2
.
Free
;
...
end
;
It works with images that have transparent parts as well.
Logged
Conscience is the debugger of the mind
klausbits
New Member
Posts: 29
Re: merge two images
«
Reply #6 on:
July 07, 2016, 04:27:50 pm »
to circular:
thank you, I'll try it.
Meanwile I worked around with
colorm:=picm.bitmap.Canvas.Pixels[nw,nh]; //color of picm, but has only 256 colors :-(
or
fpcolorm1:=picm1.bitmap.Canvas.getColor(nw,nh); //FPcolor of picm1 does not work :-(
Logged
klausbits
New Member
Posts: 29
Re: merge two images
«
Reply #7 on:
July 07, 2016, 08:43:43 pm »
many thanks for your tips. Here my own solution, I hope it works:
Code: Pascal
[Select]
[+]
[-]
begin
//see diary 6.July 2016
picm
:
=
TPicture
.
Create
;
picm1
:
=
TPicture
.
Create
;
for
n
:
=
0
to
nwidth
-
1
do
begin
// picture2[n]:= TPicture.Create; //already defined
nr
:
=
n
;
//real of n
mr
:
=
nr
*
nmax
/
nwidth
;
//real of m
m
:
=
floor
(
mr
)
;
dmr
:
=
mr
-
m
;
//fade position
Str
(
m
:
4
,
nstring
)
;
fastring
:
=
files
+
'\b'
+
nstring
+
'.jpg'
;
Str
(
m
+
1
:
4
,
nstring
)
;
fbstring
:
=
files
+
'\b'
+
nstring
+
'.jpg'
;
picm
.
LoadFromFile
(
fastring
)
;
//image 1
picm1
.
LoadFromFile
(
fbstring
)
;
//image 2
for
nh
:
=
0
to
nheight
-
1
do
begin
for
nw
:
=
0
to
nwidth
-
1
do
//for every pixel do
begin
colorm
:
=
picm
.
bitmap
.
Canvas
.
Pixels
[
nw
,
nh
]
;
//color of picm
RedGreenBlue
(
colorm
,
mRed
,
mGreen
,
mBlue
)
;
//bytes! -> only 512 different colors?
colorm1
:
=
picm1
.
bitmap
.
Canvas
.
Pixels
[
nw
,
nh
]
;
//color of picm1
RedGreenBlue
(
colorm1
,
m1Red
,
m1Green
,
m1Blue
)
;
// fpcolorm1:=picm1.bitmap.Canvas.getColor(nw,nh); //FPcolor of picm1 does not work
nred
:
=
round
(
(
1
-
dmr
)
*
mRed
+
dmr
*
m1Red
)
;
//to be scaled by 256? or 8?
ngreen
:
=
round
(
(
1
-
dmr
)
*
mGreen
+
dmr
*
m1Green
)
;
nblue
:
=
round
(
(
1
-
dmr
)
*
mBlue
+
dmr
*
m1Blue
)
;
// function RGBToColor(R, G, B: Byte): TColor;
colorn
:
=
RGBToColor
(
nred
,
ngreen
,
nblue
)
;
picture2
[
n
]
.
bitmap
.
Canvas
.
Pixels
[
nw
,
nh
]
:
=
colorn
;
//image 3
end
;
end
;
end
;
Str
(
n
:
4
,
nstring
)
;
fastring
:
=
files
+
'\bb'
+
nstring
+
'.jpg'
;
// bb... different name to not overwrite b... files of user
picture2
[
n
]
.
SaveToFile
(
fastring
)
;
//
picture2
[
n
]
.
free
;
//
end
;
Logged
circular
Hero Member
Posts: 3668
Re: merge two images
«
Reply #8 on:
July 07, 2016, 09:44:51 pm »
That's the idea.
Logged
Conscience is the debugger of the mind
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
(Moderator:
Ask
) »
merge two images
TinyPortal
© 2005-2018