
「まつり つくば 2007」より
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.dfm} uses VCLImageUtils; procedure TForm1.Button1Click(Sender: TObject); var bmp: TBitmap; filename: string; begin filename := 'C:\Home\Img\hana.png'; bmp := LoadCheckedImage(filename); if Assigned(bmp) then begin Canvas.Draw(5, 5, bmp); bmp.Free; end; end; end.
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; using System.Collections; namespace CountColors { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static int CountColors(Bitmap bmp) { if (bmp.PixelFormat != PixelFormat.Format24bppRgb) return -1; int w = bmp.Width; int h = bmp.Height; BitArray ba = new BitArray(0x1000000, false); int count = 0; int indx; int ir; BmpProc24 src = new BmpProc24(bmp); for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { ir = src.IndexR(x, y); indx = (int)((((src[ir] << 8) | src[ir - 1]) << 8) | src[ir - 2]); if (!ba[indx]) { ba[indx] = true; count++; } } src.Dispose(); return count; } private void button1_Click(object sender, EventArgs e) { Bitmap bmp = new Bitmap(@"c:\Home\ImgWork\LaFlandre.png"); StopWatch.Start(); int cn = CountColors(bmp); StopWatch.Stop(); label1.Text = cn.ToString() + " colors"; label2.Text = StopWatch.time.ToString() + " ms"; StopWatch.Start(); cn = ImgUtils.CountColors(bmp); StopWatch.Stop(); label3.Text = cn.ToString() + " colors"; label4.Text = StopWatch.time.ToString() + " ms"; bmp.Dispose(); } } }