Hi, I'm trying to load a large JPEG (3776x3850 4.0mb) from a TMemoryStream using this process:
var
W, H: integer;
Start, Stop: integer;
begin
if (Length(Files) > 0) and (Index < FileCount) then
begin
//start := GetTickCount;
Files[Index].Position := 0;
FullBmp := TBGRABitmap.Create(Files[Index]);
//stop := GetTickCount;
//New Size
W := PaintBox1.Width;
H := (FullBmp.Height * W) div FullBmp.Width;
if H > PaintBox1.Height then
begin
H := PaintBox1.Height;
W := (FullBmp.Width * H) div FullBmp.Height;
end;
//if is smaller than the paintbox height
if FullBmp.Height < PaintBox1.Height then
ResizeBmp.SetSize(FullBmp.Width, FullBmp.Height)
else
ResizeBmp.SetSize(W, H);
//Slow
FullBmp.ResampleFilter := rfBestQuality;
//Better Quality or Fast
if filter then
BGRAReplace(ResizeBmp, FullBmp.Resample(ResizeBmp.Width, ResizeBmp.Height,
rmFineResample) as TBGRABitmap)
else
BGRAReplace(ResizeBmp, FullBmp.Resample(ResizeBmp.Width, ResizeBmp.Height,
rmSimpleStretch) as TBGRABitmap);
ResizeBmp.Assign(FullBmp.Resample(ResizeBmp.Width, ResizeBmp.Height, rmSimpleStretch) as TBGRABitmap);
FullBmp.Free;
PaintBox1.Canvas.Brush.Color := clGray;
PaintBox1.Canvas.FillRect(PaintBox1.Canvas.ClipRect);
//Draw in the center
ResizeBmp.Draw(PaintBox1.Canvas, trunc((PaintBox1.Width - ResizeBmp.Width) / 2),
trunc((PaintBox1.Height - ResizeBmp.Height) / 2));
Caption := (IntToStr(stop - start));
end;
end;
It loads without any problem, but is slow at the "FullBmp := TBGRABitmap.Create(Files[Index]);" it takes more than 650ms to load to the stream to the TBRABitmap in a i7-2600 3.4GHz 12GB RAM, loading the image with the resize and displaying take up to 1100ms with the rmSimpleStretch.
There is a way to make this faster? The Draw function handles de paint process instantly once de bitmap is resized and ready.
Thanks in advance and sorry for the ENGRISH