画像の中心を設定座標になるように描く DrawImageCenterAt をつくった。
非常に簡単な関数だが、こういうのが意外と便利だったりする。

全コードをしめす。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using ImageUtils; namespace LuminanceToAlpha { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static bool LuminanceToAlpha(Bitmap bmp, bool bStretch, Color baseColor, out Bitmap result32) { result32 = null; if (bmp.PixelFormat != PixelFormat.Format24bppRgb) return false; int w = bmp.Width; int h = bmp.Height; Bitmap bw = bmp.Clone() as Bitmap; ImgUtils.GrayScale(ref bw); if (bStretch) ImgUtils.HistoStretch(ref bw); result32 = new Bitmap(w, h, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(result32); g.Clear(baseColor); g.Dispose(); BmpProc8 src = new BmpProc8(bw); BmpProc32 dst = new BmpProc32(result32); for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { dst[x, y, eRGB.a] = (byte)(255 - src[x, y]); } ImgUtils.CallDispose(dst, src, bw); return true; } public static bool SetAlpha32(ref Bitmap bmp, int percent) { if (bmp.PixelFormat != PixelFormat.Format32bppArgb) return false; int w = bmp.Width; int h = bmp.Height; double p = percent / 100d; BmpProc32 dst = new BmpProc32(bmp); for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { if (dst[x, y, eRGB.a] == 0) continue; dst[x, y, eRGB.a] = ImgUtils.AdjustByte(dst[x, y, eRGB.a] * p); } dst.Dispose(); return true; } public static void DrawImageCenterAt(Graphics g, Bitmap bmp, int x, int y) { int xx = x - bmp.Width / 2; int yy = y - bmp.Height / 2; g.DrawImage(bmp, xx, yy, bmp.Width, bmp.Height); } private void button1_Click(object sender, EventArgs e) { Bitmap bmp = new Bitmap(@"c:\Home\ImgWork\CenterAtSample3.png"); int centerX = 450; int centerY = 450; double radius = 250d; int hh; int ss = 250; int ll = 50; byte rr, gg, bb; int xx, yy; Bitmap tmp1, tmp2; Color baseColor; Graphics g = this.CreateGraphics(); for (int i = 0; i < 10; i++) { hh = 36 * i; ImgUtils.HSLToRGB(hh, ss, ll, out rr, out gg, out bb); baseColor = Color.FromArgb(rr, gg, bb); LuminanceToAlpha(bmp, true, baseColor, out tmp1); tmp2 = ImgUtils.BitmapRotate(tmp1, (float)(hh+90), Color.Transparent); SetAlpha32(ref tmp2, 85); xx = (int)(Math.Cos((double)hh / 180d * Math.PI) * radius) + centerX; yy = (int)(Math.Sin((double)hh / 180d * Math.PI) * radius) + centerY; DrawImageCenterAt(g, tmp2, xx, yy); tmp2.Dispose(); tmp1.Dispose(); } g.Dispose(); bmp.Dispose(); } } }
CenterAtSample3
