ShowHiClipping.cs
// 
// このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
// © MESCIUS inc. All rights reserved.
// 
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;

namespace DsImagingWeb.Demos
{
    // このサンプルでは、白飛びしたハイライトを含む
    // ピクセルを検出し、表示する方法を示します。
    public class ShowHiClipping
    {
        public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
        {
            var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
            using (var bmpSrc = new GcBitmap(Path.Combine("Resources", "Images", "tudor.jpg")))
            {
                // BitBltを実行するには、両方の画像の不透明度が同じである必要があります。
                bmpSrc.Opaque = opaque;
                // コピー元の画像をターゲットのビットマップ上に描画します。
                // (通常は最初にコピー元画像をリサイズしますが、このケースでは
                // コピー元画像がターゲットと同じサイズであることを前提としているため、
                // そのステップをスキップします。)
                bmp.BitBlt(bmpSrc, 0, 0);

                using (var g = bmp.CreateGraphics())
                {
                    for (int i = 0; i < bmp.PixelWidth; ++i)
                        for (int j = 0; j < bmp.PixelHeight; ++j)
                        {
                            uint px = bmp[i, j];
                            // いずれかの色が 0xFF の場合、そのピクセルの色をマゼンタに変更します。
                            if ((px & 0x000000FF) == 0x000000FF || (px & 0x0000FF00) == 0x0000FF00 || (px & 0x00FF0000) == 0x00FF0000)
                                bmp[i, j] = 0xFFFF00FF;
                        }
                    // 比較のために、右下隅に元のサンプル画像を描画します。
                    float sx = pixelSize.Width / 3, sy = pixelSize.Height / 3;
                    g.DrawImage(bmpSrc, new RectangleF(sx * 2, sy * 2, sx, sy), null, ImageAlign.StretchImage);
                }
            }
            return bmp;
        }
    }
}