- 844 名前:843 [2009/11/17(火) 22:25:52 ]
- //ソース
int pixel = 256; Bitmap bmp = null; Graphics g = null; Rectangle rect; System.IO.FileInfo fInfo = new System.IO.FileInfo(filePath); Image origin = Image.FromFile(fInfo.FullName); int wBlocks = (int)Math.Ceiling((double)origin.Width / (double)pixel); int hBlocks = (int)Math.Ceiling((double)origin.Height / (double)pixel); Console.WriteLine(filePath); for (int h = 0; h < hBlocks; h++) { for (int w = 0; w < wBlocks; w++) { bmp = new Bitmap(pixel, pixel); g = Graphics.FromImage(bmp); rect = new Rectangle((w * pixel), (h * pixel), pixel, pixel); g.DrawImage(origin, 0, 0, rect, GraphicsUnit.Pixel); string destName = fInfo.Directory + "\\" + fInfo.Name.Replace(fInfo.Extension, string.Empty) + "_" + h.ToString("000") + "_" + w.ToString("000") + ".png"; bmp.Save(destName, System.Drawing.Imaging.ImageFormat.Png); g.Dispose(); bmp.Dispose(); } } origin.Dispose();
|

|