我有一个将图像加载到 Zimage(graphcontrol) 的应用程序。我遇到的一个问题是原始图像的质量比最终显示在组件中的图像要好得多。显示的那个看起来上面有随机的黑色标记。所以我做什么:
- 将图像从文件夹加载到 TJpegimage
- 将 jpg 分配给位图
- 将位图保存到对象列表
重复上述操作,直到所有图像都加载到对象列表中
然后我创建一个位图
- 将对象列表中的第一个图像分配给它
- 在画布上绘制位图。
但它看起来比原版差很多。对此有任何帮助或想法吗?
这是加载代码。
procedure TForm1.LoadImages(const Dir: string);
var
i: Integer;
CurFileName: string;
JpgIn: TJPEGImage;
BmpOut: TBitmap;
begin
//set up progress bar
progressbar1.Min := 0;
progressbar1.Max := GetFilesCount(dir,'*.*');
Label3.Visible := true;
progressbar1.Visible := true;
//sets array for length
SetLength(hwArray,GetFilesCount(dir,'*.*'));
//sets index for object list
CurIdx := -1;
i := 0;
while True do
begin
//gets file name out of current folder
CurFileName := Format('%s%d.jpg',
[IncludeTrailingPathDelimiter(Dir), i]);
if not FileExists(CurFileName) then
Break;
//count files in folder for progress bar.
progressbar1.StepBy(1);
//creates jpgin
JpgIn := TJPEGImage.Create;
try
//loads jpgin with file
JpgIn.LoadFromFile(CurFileName);
//creates TBitmap and sets width to same as jpgs
BmpOut := TBitmap.Create;
bmpout.Width := jpgin.Width;
bmpout.Height := jpgin.Height;
try
BmpOut.Assign(JpgIn);
//adds 1 to index for object list. thus starting at 0
curIdx := curIdx+1;
//add bitmap to objectlist
CurIdx:= mylist.Add(TBitmap(bmpout));
hwArray[CurIdx][0]:=jpgin.Width;
hwArray[CurIdx][1]:=jpgin.height;
finally
end;
finally
JpgIn.Free;
end;
Inc(i);
end;
//makes sure cout is above 0 thus files added
if mylist.Count > 0 then
begin
try
CurIdx := 0;
getBitmapfromList(CurIdx,bmpout);
ZImage1.Bitmap.Assign(bmpout);
//image1.Canvas.Assign(bmpout);
finally
BmpOut.Free;
end;
end;
Label3.Visible := false;
progressbar1.Visible := false;
page:= '0';
zimage1.DblClick;
end;
函数从列表中获取位图
procedure Tform1.getBitmapfromList(index:integer;var Bitm:TBitmap);
begin
Bitm.Assign(TBitmap(mylist[index]));
if (Bitm.Width<>hwArray[index][0]) OR (Bitm.Height<>hwArray[index][1]) then begin
ShowMessage('Size differs');
Bitm.Width:=hwArray[index][0];
Bitm.Height:=hwArray[index][1];
end;
end;
下一个按钮查看下一个图像
procedure TForm1.Button3Click(Sender: TObject);
var
BmpOut: TBitmap;
begin
bmpout := TBitmap.Create;
CurIdx:= strtoint(page);
getBitmapfromList(CurIdx,bmpout);
ZImage1.Bitmap.Assign(bmpout);
//image1.Canvas.Assign(bmpout);
page := inttostr(strtoint(page) +1); //this should show next item in ilst?
zimage1.Repaint;
end;
感谢您的任何帮助或建议。
以下是图片:
http://s7.postimage.org/48mectvsp/image_Difference.png
编辑
似乎一旦我放大图像,它就会变得更好。最糟糕的 quility 是当它的全屏/完全缩小时.. 原始尺寸。