大した違いはないと思いますが、実際に画像のサイズを変更する必要はないので、サイズ変更を(試行) しないDrawImageのオーバーロードを使用してみてください。
DrawImage(bitmap,0,0);
私が言ったように、DrawImageがビットマップの幅と高さをチェックし、サイズ変更が必要ない場合は、このオーバーロードを呼び出すだけなので、違いがあるとは思えません。(実際の作業を実行せずに、1,200 万ピクセルすべてを処理しないことを願っています)。
更新: 私の熟考は間違っています。私はそれ以来知りましたが、みんなのコメントは私の古い答えを思い出させました:あなたは目的地のサイズを指定したいのです。ソースサイズと一致しますが:
DrawImage(bitmap, 0, 0, bitmap.GetWidth, bitmap.GetHeight);
bitmap
その理由は、dpiの dpi と宛先の dpi のdpi の違いによるものです。GDI+ はスケーリングを実行して、イメージを適切な「サイズ」(インチ単位) にします。
昨年 10 月以来、私が自分で学んだことは、ビットマップの「キャッシュされた」バージョンを本当に描画したいということです。CachedBitmap
GDI+ にはクラスがあります。使い方にはコツがあります。しかし、最終的には、それを行う(Delphi)コードの関数ビットがあります。
注意点は、CachedBitmap
が無効になる可能性があることです。つまり、描画には使用できません。これは、ユーザーが解像度や色深度 (リモート デスクトップなど) を変更した場合に発生します。その場合、DrawImage
は失敗し、以下を再作成する必要がありますCachedBitmap
。
class procedure TGDIPlusHelper.DrawCachedBitmap(image: TGPImage;
var cachedBitmap: TGPCachedBitmap;
Graphics: TGPGraphics; x, y: Integer; width, height: Integer);
var
b: TGPBitmap;
begin
if (image = nil) then
begin
//i've chosen to not throw exceptions during paint code - it gets very nasty
Exit;
end;
if (graphics = nil) then
begin
//i've chosen to not throw exceptions during paint code - it gets very nasty
Exit;
end;
//Check if we have to invalidate the cached image because of size mismatch
//i.e. if the user has "zoomed" the UI
if (CachedBitmap <> nil) then
begin
if (CachedBitmap.BitmapWidth <> width) or (CachedBitmap.BitmapHeight <> height) then
FreeAndNil(CachedBitmap); //nil'ing it will force it to be re-created down below
end;
//Check if we need to create the "cached" version of the bitmap
if CachedBitmap = nil then
begin
b := TGDIPlusHelper.ResizeImage(image, width, height);
try
CachedBitmap := TGPCachedBitmap.Create(b, graphics);
finally
b.Free;
end;
end;
if (graphics.DrawCachedBitmap(cachedBitmap, x, y) <> Ok) then
begin
//The calls to DrawCachedBitmap failed
//The API is telling us we have to recreate the cached bitmap
FreeAndNil(cachedBitmap);
b := TGDIPlusHelper.ResizeImage(image, width, height);
try
CachedBitmap := TGPCachedBitmap.Create(b, graphics);
finally
b.Free;
end;
graphics.DrawCachedBitmap(cachedBitmap, x, y);
end;
end;
はcachedBitmap
参照によって渡されます。キャッシュされたDrawCachedBitmap
バージョンへの最初の呼び出しが作成されます。次に、後続の呼び出しでそれを渡します。次に例を示します。
Image imgPrintInvoice = new Image.FromFile("printer.png");
CachedBitmap imgPrintInvoiceCached = null;
...
int glyphSize = 16 * (GetCurrentDpi() / 96);
DrawCachedBitmap(imgPrintInvoice , ref imgPrintInvoiceCached , graphics,
0, 0, glyphSize, glyphSize);
現在の DPI を考慮して、ルーチンを使用してボタンにグリフを描画します。Internet Explorer チームは、ユーザーが高 dpi を実行しているときに画像を描画するために同じことを使用できました (つまり、GDI+ を使用しているため、ズーム画像の描画が非常に遅くなります)。