在将图像保存到TJPEGImage之前,我遇到了一些问题。
第1步: *(JPEG)我想在图片顶部添加一些文字“一个新行..不在图片上.. 我怎么能这样做?
第2步: *我希望将图像调整为(cm)示例: 200cm x 300cm / 320DPI 等。
第3步 *使用压缩保存JPEG 什么是最好的无损方法?
我试过DEVEXPRESS图像组件,但它保存了400MB的图像......我找不到任何压缩方法。
任何可以帮助我吗?谢谢大家
答案 0 :(得分:2)
JPEG通常是内在压缩的,虽然有一个无损变体(也是压缩的,只是以不同的方式避免丢失)。
我不熟悉用于处理JPEG的DevExpress工具,但任何与JPEG处理有关的属性(应该)几乎肯定能够控制所使用的压缩程度,这可能包括也可能不包括Lossless
。
但是,根据您看到的结果文件大小,您的案例中会出现 压缩。
如果您要在200cm x 300cm
调整为78" x 118"
(320 dpi
),那么您生成的图像(以整数形式)25,000 x 38,000 px
。这是 950 MEGAPIXEL 图片!
此类图像would be over 1GB in size的无损(至少压缩)JPEG表示,因此,如果您“仅”获得400MB,那么显然已经有一些非常重要的压缩工作了。
您的问题是您似乎想要压缩图像更多(使尺寸小于400MB) AND 您想要使用无损压缩,这意味着压缩它 less (并使文件更大)。
所以我认为你需要决定你真正想要的东西(然后你可能会发现你已经拥有它)。
答案 1 :(得分:1)
首先应使用
将jpeg图像保存到位图bmp.Assign(jpegimage);
bmp.Canvas.TextOut(5, 5, 'SomeText');
然后调整位图的大小 我使用这个功能
procedure SmoothResize(Src, Dst: TBitmap);
var
x, y: Integer;
xP, yP: Integer;
xP2, yP2: Integer;
SrcLine1, SrcLine2: pRGBArray;
t3: Integer;
z, z2, iz2: Integer;
DstLine: pRGBArray;
DstGap: Integer;
w1, w2, w3, w4: Integer;
begin
Src.PixelFormat := pf24Bit;
Dst.PixelFormat := pf24Bit;
if (Src.Width = Dst.Width) and (Src.Height = Dst.Height) then
Dst.Assign(Src)
else
begin
DstLine := Dst.ScanLine[0];
DstGap := Integer(Dst.ScanLine[1]) - Integer(DstLine);
xP2 := MulDiv(pred(Src.Width), $10000, Dst.Width);
yP2 := MulDiv(pred(Src.Height), $10000, Dst.Height);
yP := 0;
for y := 0 to pred(Dst.Height) do
begin
xP := 0;
SrcLine1 := Src.ScanLine[yP shr 16];
if (yP shr 16 < pred(Src.Height)) then
SrcLine2 := Src.ScanLine[succ(yP shr 16)]
else
SrcLine2 := Src.ScanLine[yP shr 16];
z2 := succ(yP and $FFFF);
iz2 := succ((not yp) and $FFFF);
for x := 0 to pred(Dst.Width) do
begin
t3 := xP shr 16;
z := xP and $FFFF;
w2 := MulDiv(z, iz2, $10000);
w1 := iz2 - w2;
w4 := MulDiv(z, z2, $10000);
w3 := z2 - w4;
DstLine[x].rgbtRed := (SrcLine1[t3].rgbtRed * w1 +
SrcLine1[t3 + 1].rgbtRed * w2 +
SrcLine2[t3].rgbtRed * w3 + SrcLine2[t3 + 1].rgbtRed * w4) shr 16;
DstLine[x].rgbtGreen :=
(SrcLine1[t3].rgbtGreen * w1 + SrcLine1[t3 + 1].rgbtGreen * w2 +
SrcLine2[t3].rgbtGreen * w3 + SrcLine2[t3 + 1].rgbtGreen * w4) shr 16;
DstLine[x].rgbtBlue := (SrcLine1[t3].rgbtBlue * w1 +
SrcLine1[t3 + 1].rgbtBlue * w2 +
SrcLine2[t3].rgbtBlue * w3 +
SrcLine2[t3 + 1].rgbtBlue * w4) shr 16;
Inc(xP, xP2);
end; {for}
Inc(yP, yP2);
DstLine := pRGBArray(Integer(DstLine) + DstGap);
end; {for}
end; {if}
end;
然后将它们保存为jpeg图像
JPG.assign(bitmap)
JPG.CompressionQuality := 99;
JPG.Compress;