4

画像を Zimage(graphcontrol) に読み込むアプリを入手しました。私が抱えている問題の 1 つは、元の画像がコンポーネントに表示される画像よりもはるかに優れていることです。表示されているものには、ランダムな黒いマークが付いているように見えます。では私は何をすべきか:

  • フォルダから 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

編集

画像をズームインすると、より良くなるようです。最悪のクリティは、フルスクリーン/ズームアウトしたときです..元のサイズ。

4

1 に答える 1

2
  • a)すべての画像のサイズが異なると思います。表示される画像「ZImage1」の高さまたは幅が常に同じである必要がある場合(2 つのうちの 1 つ、またはストレッチ フィット == 低品質で作成されている) の比率を決定する必要があります (original.height / original.width)。 "ZImage1" (高さまたは幅のいずれか)は、新しい関係で計算する必要があります。
  • b) ZImage1.AutoSize:=false を設定します。
  • 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.Width と bmpout.Heightの自動bmpout.Assign(TBitmap(mylist[CurIdx]));設定が存在しない可能性があります。

ヒント:

高さと幅を格納するための追加の配列を作成します。

....
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;
....

プロシージャを作成します EDIT : テストを入れます。

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,'*.*'));
....
于 2012-06-15T09:22:19.163 に答える