Skip to content

Commit

Permalink
PNG圖片處理支持多選
Browse files Browse the repository at this point in the history
  • Loading branch information
lemingcen committed May 1, 2019
1 parent 446533f commit bb193d0
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions WorldOfTheThreeKingdomsEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,31 +362,35 @@ private void btnPNGAlpha_Click(object sender, RoutedEventArgs e)
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "待處理圖片 (*.png)|*.png";
openFileDialog.InitialDirectory = @"Content\Textures";
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == true)
{
String filename = openFileDialog.FileName;
var filenames = openFileDialog.FileNames;

using (var img = System.Drawing.Image.FromFile(filename))
foreach (var filename in filenames)
{
var bitmap = new Bitmap(img, img.Width, img.Height);
using (var img = System.Drawing.Image.FromFile(filename))
{
var bitmap = new Bitmap(img, img.Width, img.Height);

var target = new Bitmap(img.Width, img.Height);
var target = new Bitmap(img.Width, img.Height);

using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(target, 0, 0);
for (int h = 0; h < bitmap.Height; h++)
using (Graphics g = Graphics.FromImage(bitmap))
{
for (int w = 0; w < bitmap.Width; w++)
g.DrawImage(target, 0, 0);
for (int h = 0; h < bitmap.Height; h++)
{
var color = bitmap.GetPixel(w, h);
color = PremultiplyAlpha(color);
target.SetPixel(w, h, color);
for (int w = 0; w < bitmap.Width; w++)
{
var color = bitmap.GetPixel(w, h);
color = PremultiplyAlpha(color);
target.SetPixel(w, h, color);
}
}
}
}

target.Save(filename.Replace(".png", "-alpha.png"), System.Drawing.Imaging.ImageFormat.Png);
target.Save(filename.Replace(".png", "-alpha.png"), System.Drawing.Imaging.ImageFormat.Png);
}
}

MessageBox.Show("PNG圖片PreMultiplied!");
Expand Down

0 comments on commit bb193d0

Please sign in to comment.