私の隠しオブジェクト ゲームでは、AnsX1、AnsX2、AnsY1、AnsY2 がオブジェクトの位置のピクセル座標である次のコードで見つかったオブジェクトを円のイメージでマークしたいと考えています。円の画像は、ピクセル座標でマークされたオブジェクトのサイズに従ってサイズ変更する必要があります
imgCat.Source = writeableBmp;
WriteableBitmap wbCircle = new WriteableBitmap(AnsX2 - AnsX1, AnsY2 - AnsY1);
wbCircle = new WriteableBitmap(0, 0).FromContent("Images/circle.png");
//Just to make sure the boundary is correct so I draw the green rec around the object
writeableBmp.DrawRectangle(AnsX1, AnsY1, AnsX2, AnsY2, Colors.Green);
Rect sourceRect = new Rect(0, 0, writeableBmp.PixelWidth, writeableBmp.PixelHeight);
Rect destRect = new Rect(AnsX1, AnsY1, wbCircle.PixelWidth, wbCircle.PixelHeight);
writeableBmp.Blit(destRect, wbCircle, sourceRect);
writeableBmp.Invalidate();
私の問題は、1 つの大きな円ではなく、上部の長方形領域を埋めるいくつかの小さな円があることです (画像を参照)。
EDIT 1: @Rene 応答に基づいて、コードを次のように変更しました
imgCat.Source = writeableBmp;
//Just to make sure the boundary is correct so I draw the green rec around the object
writeableBmp.DrawRectangle(AnsX1, AnsY1, AnsX2, AnsY2, Colors.Green);
WriteableBitmap wbCircle = new WriteableBitmap(0, 0).FromContent("Images/circle.png");
wbCircle = wbCircle.Resize(AnsX2 - AnsX1, AnsY2 - AnsY1, WriteableBitmapExtensions.Interpolation.Bilinear);
Rect sourceRect = new Rect(0, 0, writeableBmp.PixelWidth, writeableBmp.PixelHeight);
Rect destRect = new Rect(AnsX1, AnsY1, AnsX2 - AnsX1, AnsY2 - AnsY1);
writeableBmp.Blit(destRect, wbCircle, sourceRect);
writeableBmp.Invalidate();
これが結果です
これを修正できたら、より大きくて品質の高い circle.png を使用します。