我有一个应用程序将图像加载到Zimage(graphcontrol)。我遇到的一个问题是原始图像比最终显示在组件中的图像质量好得多。显示的那个看起来像是随机的黑色标记。所以我做了什么:
重复上述内容,直到所有图像都加载到对象列表中
然后我创建一个位图
但它看起来比原版差很多。对此有何帮助或想法?
这是加载代码。
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
似乎一旦我放大图像就会变得更好。最糟糕的是,它的全屏/缩放一直都是原始大小。
答案 0 :(得分:2)
c)设置ZImage1.Stretch:= false;
d)bmpout.Width和Height必须设置为当前mylist[CurIdx]
大小。
bmpout.Assign(TBitmap(mylist[CurIdx])); Zimage1.Bitmap.Width := bmpout.Width; Zimage1.Bitmap.Height := bmpout.Height; ZImage1.Bitmap.Assign(bmpout);
注意:
你不 * 将 *分配给mylist ..你存储它CurIdx:= mylist.Add(TBitmap(bmpout));
我看不出你是如何创建“mylist”的。
也许这就是原因,如果你想要它回到bmpout.Assign(TBitmap(mylist[CurIdx]));
,也许有没有自动设置bmpout.Width和bmpout.Height。
提示:
创建一个额外的数组来存储高度和宽度。
....
JpgIn.LoadFromFile(CurFileName);
BmpOut := TBitmap.Create;
bmpout.Width := jpgin.Width;
bmpout.Height := jpgin.Height;
....
CurIdx:= mylist.Add(TBitmap(bmpout));
hwArray[CurIdx][0]:=jpgin.Width;
hwArray[CurIdx][1]:=jpgin.height;
....
制作程序 编辑:对其进行测试;
procedure 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;
用它来表示:
....
getBitmapfromList(CurIdx,bmpout);
....
ZImage1.Bitmap.Assign(bmpout);
....
编辑:创建 hwArray
type
Tarray2size = Array[0..1] of integer;
....
var
hwArray : Array of Tarray2size;
....
procedure TForm1.LoadImages(const Dir: string);
....
begin
//set up progress bar
progressbar1.Min := 0;
showmessage(inttostr(GetFilesCount(dir,'*.*')));
SetLength(hwArray,GetFilesCount(dir,'*.*'));
....