Exemplo n.º 1
0
        private void btnSaveNewImage_Click(object sender, EventArgs e)
        {
            if (txtAscii.Text == String.Empty)
            {
                return;
            }

            

            Font textFont = new System.Drawing.Font(txtAscii.Font.Name, (float)numFontSize.Value, txtAscii.Font.Style);
            Bitmap textBitmap = originalBitmap.ASCIIFilter((int)numPixelsToChar.Value).TextToImage(textFont, (float)(numZoom.Value / 100));

            if (textBitmap != null)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title = "Specify a file name and file path";
                sfd.Filter = "Png Images(*.png)|*.png|Jpeg Images(*.jpg)|*.jpg";
                sfd.Filter += "|Bitmap Images(*.bmp)|*.bmp";

                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string fileExtension = Path.GetExtension(sfd.FileName).ToUpper();
                    ImageFormat imgFormat = ImageFormat.Png;

                    if (fileExtension == "BMP")
                    {
                        imgFormat = ImageFormat.Bmp;
                    }
                    else if (fileExtension == "JPG")
                    {
                        imgFormat = ImageFormat.Jpeg;
                    }

                    StreamWriter streamWriter = new StreamWriter(sfd.FileName, false);
                    textBitmap.Save(streamWriter.BaseStream, imgFormat);
                    streamWriter.Flush();
                    streamWriter.Close();

                    textBitmap.Dispose();
                }
            }
        }