2

GDI ライブラリを使用して画像のサイズを変更し、以前よりも大きくなるようにサイズを変更すると、ブレンドが発生しないようにしたいと考えています。(ペイント プログラムで画像を拡大するときのように)

例: 画像の幅が 2 ピクセル、高さが 2 ピクセル
(白、白、
白、黒)
で、サイズを 100% に変更すると、高さ 4 ピクセル x 4 ピクセル
(白、白、白、白、白、
白) になります。 、白、白、
白、白、黒、黒、
白、白、黒、黒)

これを実現するために、グラフィック オブジェクトのどの InterpolationMode または Smoothing モード (またはその他のプロパティ) を使用できますか? これまでに試したすべての組み合わせで、テスト イメージにグレーが表示されます。

これが私が使用しているコードです

    /// <summary>
    /// Do the resize using GDI+
    /// Credit to the original author
    /// http://www.bryanrobson.net/dnn/Code/Imageresizing/tabid/69/Default.aspx
    /// </summary>
    /// <param name="srcBitmap">The source bitmap to be resized</param>
    /// <param name="width">The target width</param>
    /// <param name="height">The target height</param>
    /// <param name="isHighQuality">Shoule the resize be done at high quality?</param>
    /// <returns>The resized Bitmap</returns>

    public static Bitmap Resize(Bitmap srcBitmap, int width, int height, bool isHighQuality)
    {
        // Create the destination Bitmap, and set its resolution
        Bitmap destBitmap = new Bitmap((int)Convert.ToInt32(width), (int)Convert.ToInt32(height), PixelFormat.Format24bppRgb);
        destBitmap.SetResolution(srcBitmap.HorizontalResolution, srcBitmap.VerticalResolution);

        // Create a Graphics object from the destination Bitmap, and set the quality
        Graphics grPhoto = Graphics.FromImage(destBitmap);
        if (isHighQuality)
        {
            grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
        }
        else
        {
            grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; //? this doesn't work
            grPhoto.InterpolationMode = InterpolationMode.NearestNeighbor; //? this doesn't work


        }
        // Do the resize
        grPhoto.DrawImage(srcBitmap,
              new Rectangle(0, 0, width, height),
              new Rectangle(0, 0, srcBitmap.Width, srcBitmap.Height),
              GraphicsUnit.Pixel);

        grPhoto.Dispose();
        return destBitmap;
    }
4

3 に答える 3

0

あなたが私に悪いことをしているようには見えません。InterpolationMode に関する Microsoft の指示を参照してください。

http://msdn.microsoft.com/en-us/library/ms533836(VS.85).aspx

この関数は完全に機能しているのに、間違ったパラメーターを指定したり、結果を正しく表示していない可能性があります。

于 2009-03-30T01:06:09.190 に答える
0

イメージを描画してソースの四角形を渡すときは、元のイメージのズームイン部分のみを渡し、それをより広い領域に描画します。ユーザーがズームインすると、ある時点で表示領域に画像全体が表示されなくなります。したがって、どのソース領域がまだ表示されている必要があるかを判断し、それのみをペイントします。

于 2009-03-29T04:38:03.980 に答える