I couldn't help myself so once again I'm asking you for help. This time I will show the problem better than last time, I hope.
I'm writing a program to check if Quantization have any influence on image sizes. To do that I need to have implemented :
- Open PNG Image (done)
- "Quantize" pixel by pixel till the end of the image (done)
- Save (this is the problem)
PNG filter method 0 defines five basic filter types: Type Name
0 - None, 1 - Sub, 2 - Up, 3 - Average, 4 - Paeth
And now I'm standing with an image in memory that I want to save using one of that filters, but after checking multiple of PNG libraries, none of them allow me to choose one. Can anyone help me with that or at least with one filter? Here you go with some code :
private void btnSelectImg_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "PNG Image | *.png";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string imgPath = openFileDialog1.FileName;
tbSourceImageFile.Text = imgPath;
string[] NameCutter = imgPath.Split('\\');
lblFileName.Text = NameCutter.Last();
ImageToWork = Image.FromFile(imgPath);
System.Drawing.Imaging.ImageFormat Format = ImageToWork.RawFormat;
tbInfo.Text += string.Format("Resolution : {0}x{1} | Bits : {2:n0} | Format : {3}", ImageToWork.Width, ImageToWork.Height, ImageToWork.Width * ImageToWork.Height, GetFilenameExtension(Format));
}
}
private void btnSave_Click(object sender, EventArgs e)
{
#region Check Image
if (tbSourceImageFile.Text == "")
{
MessageBox.Show("File not selected. Select file first.");
return;
}
#endregion
#region Operations on image
Bitmap Image111 = new Bitmap(tbSourceImageFile.Text, true);
#region Progress Bar Settings
ProgressBar.Visible = true;
ProgressBar.Value = 1;
ProgressBar.Maximum = Image111.Width;
ProgressBar.Step = 1;
#endregion
if (cboxEnableScale.Checked == true)
{
int red, green, blue, red2=0, blue2=0, green2=0;
int scale = int.Parse(cbSelectorScale.SelectedItem.ToString());
for (int w = 0; w < Image111.Width; w++)
{
for (int h = 0; h < Image111.Height; h++)
{
Color PixelColor = Image111.GetPixel(w, h);
#region Quantization
red = PixelColor.R;
green = PixelColor.G;
blue = PixelColor.B;
Color newColor = Color.FromArgb(Valuator_v3(red, scale), Valuator_v3(green, scale), Valuator_v3(blue, scale));
Image111.SetPixel(w, h, newColor);
#endregion
}
ProgressBar.PerformStep();
}
}
#endregion
#region Saving
string SaveDirectory = tbSaveDestination.Text + '\\' + tbSaveFileName.Text + ".bmp";
SaveDirectory = tbSaveDestination.Text + '\\' + tbSaveFileName.Text + ".jpeg";
Image111.Save(SaveDirectory, System.Drawing.Imaging.ImageFormat.Png);
ProgressBar.Visible = false;
MessageBox.Show("Saved successfully.");
#endregion
}
In region "Saving" I want to select which filter will be used and save it using it.