我有一个将图像加载到 Zimage(graphcontrol)的应用程序。我遇到的问题是原始图像的质量比最终显示在组件中的图像要好得多。显示出来的那个看起来像是随机黑点。所以我做的是:
下一步按钮,可查看下一张图片。
感谢任何帮助或建议。
以下是图片: http://s7.postimage.org/48mectvsp/image_Difference.png 编辑
似乎一旦我放大图像,它就会变得更好。最差的质量是当它处于全屏幕/缩小到最小的状态时...原始大小。
- 从文件夹中加载图像到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 编辑
似乎一旦我放大图像,它就会变得更好。最差的质量是当它处于全屏幕/缩小到最小的状态时...原始大小。
TBitmap
实例并在画布上呈现不会降低图像质量。Glen,我猜你的问题在于当你渲染图像时宽高比不正确(如果我没错的话,你正在使用StretchDraw
)。当然,你需要考虑到当你拉伸图像(缩放)时,它自然会失去质量(你需要以某种方式重新采样来减少质量损失)。 - TLamaImage1.Bitmap.Assign(bmpout);
更改为Image1.Picture.Bitmap.Assign(bmpout);
。 - moskito-x