将EXIF曝光时间计算为分数(Delphi) [英] Calculating EXIF exposure time as a fraction (Delphi)
问题描述
我试图将EXIF曝光时间显示为几分之一秒,但我没有得到预期的结果,可能是一个小错误.
I am trying to display EXIF exposure time as a fraction of seconds but I am not getting expected result, probably a small mistake.
我发现有两个例程可以进行计算,但是都带来不同的结果.
I have found two routines that do the calculation but both bring diffrent and wrong result.
我遇到的值是:"0.0806451612903226"的值是扩展类型.
The value I am having problem is: "0.0806451612903226" value is of type Extended.
DecimalToFractStr给我:结果是"16129/200000", DecToFrac给我:结果是"5/62"
DecimalToFractStr give me: "16129/200000" as a result, DecToFrac gives me: "5/62" as a result
由于每个人都可以得到预期的结果,因此结果应为"1/12"(诀窍是什么).当我右键单击资源管理器中的图像并查看详细信息时,将获得此值.如何在我的应用程序中获取它?希望有人可以在这里帮助我.
Expected result should be "1/12" since everyone is getting it (what is the trick). When I right click image in explorer and view details I get this value. How do I get it in my application? Hope someone can help me here.
亲切问候 罗伊·科沃(Roy M Klever)
Kind Regards Roy M Klever
已解决! 确定,经过一些测试,我弄清楚了.使用DecToFrac的结果,他们可以简单地将其与左侧的结果进行整数除法. 5 div 5 = 1/62 div 5 = 12,所以我剩下想要的结果1/12.
SOLVED! Ok after some testing I figured it out. Using the result from DecToFrac they simply integer divide it with the result from the left side. 5 div 5 = 1 / 62 div 5 = 12 so I am left with wanted result 1 / 12.
感谢您的所有输入.
亲切问候 罗伊·M·克莱沃(Roy M Klever)
Kind Regards Roy M Klever
procedure DecimalToFract(value: double; AllowedDecimals: integer; var num, den:
integer);
var
d, i: integer;
ex: boolean;
begin
d := Trunc(power(10, AllowedDecimals));
num := Trunc(value * d);
den := d;
repeat
ex := true;
for i := 10 downto 2 do
if ((num mod i) = 0) and ((den mod i) = 0) then
begin
num := num div i;
den := den div i;
ex := false;
end;
until ex;
end;
function DecimalToFractStr(value: double): string;
var
num, den: integer;
begin
DecimalToFract(value, 6, num, den);
if den = 1 then
result := inttostr(num)
else
result := inttostr(num) + '/' + inttostr(den);
end;
function Dec2Frac(f: Double): String;
var
df: Double;
lUpperPart: Integer;
lLowerPart: Integer;
begin
lUpperPart := 1;
lLowerPart := 1;
df := lUpperPart / lLowerPart;
While (df <> f) do
begin
If (df < f) Then
lUpperPart := lUpperPart + 1
Else
begin
lLowerPart := lLowerPart + 1;
lUpperPart := Trunc(f * lLowerPart);
end;
df := lUpperPart / lLowerPart;
end;
if lLowerPart = 1 then
result := IntToStr(lUpperPart)
else
result := IntToStr(lUpperPart) + '/' + IntToStr(lLowerPart);
end;
推荐答案
1/12实际上不是该值的正确结果.
1/12 is not actually a correct result for that value.
也许它们可能具有某种快照"查找表,即该值与递增值列表中的值最接近1/12?
Maybe they perhaps have some kind of "snap to" lookup table i.e. this value is closest to 1/12 from a list of incremented values?
这篇关于将EXIF曝光时间计算为分数(Delphi)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!