/// <summary> /// 彩度・明度ビューを描画する。 /// </summary> /// <param name="g">Graphicsオブジェクト</param> private void PaintSVArea(Graphics g) { if ((svRenderBuffer == null) && (svArea.Width > 2) && (svArea.Height > 2)) { svRenderBuffer = ImageBuffer.Create(svArea.Width - 2, svArea.Height - 2); svDisplayImage = null; } if ((svDisplayImage == null) && (svRenderBuffer != null)) { // ImageBufferを再レンダリング RenderSVImageBuffer(); svDisplayImage = svRenderBuffer.GetImage(); } if (svDisplayImage != null) { g.DrawImage(svDisplayImage, svArea.X + 1, svArea.X + 1, svArea.Width - 2, svArea.Height - 2); } using (Pen pen = new Pen((colorHSV.Value < 0.5f) ? Color.White : Color.Black)) { // 選択されているsaturation, valueの位置に十字カーソルを書く int x = svArea.Left + Convert.ToInt32((1.0f - colorHSV.Saturation) * (svArea.Width - 2)); g.DrawLine(pen, x, svArea.Top, x, svArea.Bottom); int y = svArea.Top + Convert.ToInt32((1.0f - colorHSV.Value) * (svArea.Height - 2)); g.DrawLine(pen, svArea.Left, y, svArea.Right, y); } using (Pen pen = new Pen(Color.Black)) { g.DrawRectangle(pen, svArea.Left, svArea.Top, svArea.Width - 1, svArea.Height - 1); } }
/// <summary> /// 処理する。 /// </summary> /// <param name="filePaths">ファイルパス</param> public void Process(string[] filePaths) { foreach (string filePath in filePaths) { ImageBuffer srcBuffer; ImageFormat imageFormat; // データを読み出す。 // usingブロックをすぐに閉じるのは、 // こうしないとファイルをオープンしっぱなしになるため。 using (Image srcImage = ReadImage(filePath)) { srcBuffer = ImageBuffer.CreateFrom(srcImage); imageFormat = srcImage.RawFormat; } ImageBuffer dstBuffer = Process(srcBuffer); using (Image dstImage = dstBuffer.GetImage()) { string fileName = System.IO.Path.GetFileName(filePath); string dir = GetOutputDirectory(); if (string.IsNullOrEmpty(dir)) { dir = System.IO.Directory.GetCurrentDirectory(); } string dstPath = System.IO.Path.Combine(dir, fileName); dstImage.Save(dstPath, imageFormat); } } }
/// <summary> /// 色相領域を描画する。 /// </summary> /// <param name="g"></param> private void PaintHueArea(Graphics g) { if ((hueRenderBuffer == null) && (hueArea.Width > 2) && (hueArea.Height > 2)) { hueRenderBuffer = ImageBuffer.Create(hueArea.Width - 2, hueArea.Height - 2); hueDisplayImage = null; } if ((hueDisplayImage == null) && (hueRenderBuffer != null)) { // ImageBufferを再レンダリング RenderHueImageBuffer(); hueDisplayImage = hueRenderBuffer.GetImage(); } if (hueDisplayImage != null) { g.DrawImage(hueDisplayImage, hueArea.X + 1, hueArea.Y + 1, hueArea.Width - 2, hueArea.Height - 2); } using (Pen pen = new Pen(Color.Black)) { // 選択されているHueの位置に十字カーソルを書く int x = hueArea.Left + Convert.ToInt32(colorHSV.Hue / 360.0f * (hueArea.Width - 2)); g.DrawLine(pen, x, hueArea.Top, x, hueArea.Bottom); } using (Pen pen = new Pen(Color.Black)) { g.DrawRectangle(pen, hueArea.Left, hueArea.Top, hueArea.Width - 1, hueArea.Height - 1); } }
/// <summary> /// 連番名を付けて画像を書き出す。 /// {dir}\{baseName}XXXXX.png のようなファイル名で書き出しを行う。 /// </summary> /// <param name="dir">書き出し先ディレクトリ</param> /// <param name="baseName">ファイル名のベース</param> /// <param name="image">画像</param> public static void WriteImageWithNewName(string dir, string baseName, ImageBuffer image) { string path = GeneratePathNotExists(dir, baseName, ".png"); if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } using (Image im = image.GetImage()) { im.Save(path, System.Drawing.Imaging.ImageFormat.Png); } }
/// <summary> /// キャラチップデータをエクスポートする /// </summary> public static void ExportCharaChip(GeneratorSetting setting) { if (string.IsNullOrEmpty(setting.ExportSetting.ExportFilePath)) { throw new ArgumentException("ExportFilePath not specified."); } Size charaChipSize = setting.ExportSetting.CharaChipSize; int charaPlaneWidth = charaChipSize.Width * 3; int charaPlaneHeight = charaChipSize.Height * 4; int exportImageWidth = charaPlaneWidth * setting.HorizontalCount; int exportImageHeight = charaPlaneHeight * setting.VerticalCount; ImageBuffer exportBuffer = ImageBuffer.Create(exportImageWidth, exportImageHeight); for (int charaY = 0; charaY < setting.VerticalCount; charaY++) { for (int charaX = 0; charaX < setting.HorizontalCount; charaX++) { int index = charaY * setting.HorizontalCount + charaX; if (index >= setting.GetCharacterCount()) { continue; } try { Character character = setting.GetCharacter(index); // キャラクターをレンダリングする。 ImageBuffer charaChipImage = RenderCharaChip(setting.GetCharacter(charaY * 4 + charaX), charaChipSize); // レンダリングした画像をエクスポートバッファにコピーする。 exportBuffer.WriteImage(charaChipImage, charaX * charaPlaneWidth, charaY * charaPlaneHeight); } catch (Exception e) { throw new Exception($"Character{(index + 1)}:{e.Message}"); } } } Image image = null; image = exportBuffer.GetImage(); image.Save(setting.ExportSetting.ExportFilePath); }
/// <summary> /// エクスポート処理 /// </summary> private void ExportProc() { var lastFileName = Properties.Settings.Default.LastExportPath; if (System.IO.File.Exists(lastFileName)) { saveFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(lastFileName); saveFileDialog.FileName = System.IO.Path.GetDirectoryName(lastFileName); } saveFileDialog.Filter = Properties.Resources.FILEFILTER_IMAGE; saveFileDialog.FilterIndex = 0; if (saveFileDialog.ShowDialog(this) != DialogResult.OK) { return; } Properties.Settings.Default.LastExportPath = saveFileDialog.FileName; var exportFileName = saveFileDialog.FileName; // サクッと生成する。 ImageBuffer imageBuffer = ImageBuffer.Create(faceImageEntrySet.ExportWidth, faceImageEntrySet.ExportHeight); for (int i = 0; i < faceImageEntrySet.EntryCount; i++) { var entry = faceImageEntrySet.GetEntry(i); if (!string.IsNullOrEmpty(entry.FileName)) { using (var srcImage = Image.FromFile(entry.FileName)) { var writeImage = ImageBuffer.CreateFrom(srcImage); int dstXOffs = entry.Width * (i % faceImageEntrySet.HorizontalEntryCount); int dstYOffs = entry.Height * (i / faceImageEntrySet.HorizontalEntryCount); imageBuffer.WriteImage(writeImage, entry.X, entry.Y, dstXOffs, dstYOffs, entry.Width, entry.Height); } } } using (var image = imageBuffer.GetImage()) { image.Save(exportFileName); } }
/// <summary> /// 更新する。 /// </summary> private void UpdateImage() { int fillAreaWidth = (int)(numericUpDownWidth.Value); int fillAreaHeight = (int)(numericUpDownHeight.Value); int outlineWidth = (int)(numericUpDownOutline.Value); Color c = labelColor.BackColor; int width = fillAreaWidth + outlineWidth * 2; int height = fillAreaHeight + outlineWidth * 2; if ((width > 0) || (height > 0)) { ImageBuffer imageBuffer = ImageBuffer.Create(width, height); PaintRoundRect(imageBuffer, outlineWidth, c); pictureBox.Image = imageBuffer.GetImage(); } else { pictureBox.Image = null; } }
/// <summary> /// 処理する。 /// </summary> /// <param name="paths">ファイルパス</param> public void Process(string[] paths) { foreach (string filePath in paths) { using (Image srcImage = ReadImage(filePath)) { ImageBuffer srcBuffer = ImageBuffer.CreateFrom(srcImage); ImageBuffer dstBuffer = SequentialProcess(srcBuffer); using (Image dstImage = dstBuffer.GetImage()) { string fileName = System.IO.Path.GetFileName(filePath); string dir = setting.OutputDirectory; if (string.IsNullOrEmpty(dir)) { dir = System.IO.Directory.GetCurrentDirectory(); } string dstPath = System.IO.Path.Combine(dir, fileName); dstImage.Save(dstPath, srcImage.RawFormat); } } } }