4

私はここのようなイメージリストにイメージを追加しています - Add a png image to a imagelist in runtime using Delphi XE。このリストからビットマップを取得してハード ドライブに保存すると、問題が発生します。

bmp:=tbitmap.create;
imagelist.getbitmap(0,bmp);
bmp.savetofile()

これは、多くの白い bmp ファイルと、'image' を含むいくつかのファイルで発生します。非常に簡単なはずですが、何が悪いのかわかりません。

LE: 例は以下の疑似コード.コードのようでした:

リストを埋める

   FImageList := TImageList.Create(nil);
   FImageList.Masked:=false;
   FImageList.ColorDepth:=cd32bit;
   FImageList.SetSize(32,32);//I am sure that all images are 32x32
   while not dsTemp.eof do//dstemp is a Tdatasetdescendant
    begin
     ststream := dsTemp.CreateBlobStream(dsTemp.FieldByName('FLAG'), bmRead);

     pngImage := TPngImage.Create;
     pngImage.LoadFromStream(ststream);

     btBitmap := TBitmap.Create;
     btBitmap.PixelFormat := pf32bit;
     btBitmap.Width := pngImage.Width ;
     btBitmap.Height := pngImage.Height ;
     pngImage.AssignTo(btBitmap);
     btBitmap.AlphaFormat:=afIgnored;

     res := FImageList.Add(btBitmap,nil);
//     pngImage.savetofile('C:\a\'+inttostr(res)+'.png');-works. image is ok
//     btBitmap.savetofile('C:\a\'+inttostr(res)+'.bmp');-works. image is ok
     dsTemp.Next;
     freeandnil(btBitmap);
     freeandnil(pngImage);
    end;

ビットマップの読み込みに関する問題

 for iPos := 0 to FImageList.Count-1 do
  begin
     btBitmap := tbitmap.create;
     FImageList.GetBitmap(iPos,btBitmap);
     btBitmap.savetofile('C:\a\'+inttostr(iPos)+'thr.bmp');//creates the bitmap, but it is white
  end;

質問が閉じられた後に編集してください:もっと反対票をお願いします!ありがとう

4

2 に答える 2

6

Uwe Raabe の回答に基づいて、私はそれを機能させます。

 for iPos := 0 to FImageList.Count-1 do
  begin
     btBitmap := tbitmap.create;
     btBitmap.PixelFormat := pf32bit;
     btBitmap.AlphaFormat := afIgnored;
     FImageList.GetBitmap(iPos,btBitmap);
     btBitmap.savetofile('C:\a\'+inttostr(iPos)+'thr.bmp');
  end;

ビットマップが正しく保存されるようになりました。

于 2012-11-13T08:02:20.530 に答える
5

動作しない画像の例を挙げていただければ、間違いなく役立ちます。その間、このコードを試してみることができます。

bmp.PixelFormat := pf32bit;
bmp.AlphaFormat := afDefined;
ImageList.GetBitmap(0, bmp);
于 2012-11-12T22:39:26.433 に答える