using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace photocaption
{
public partial class Form1 : Form
{
public Image img;
public string st;
public Form1()
{
InitializeComponent();
}
private void btnLoad_Click(object sender, EventArgs e)
{
listbox.Items.Clear();
DirectoryInfo dinfo = new DirectoryInfo(@"C:\abcd");
FileInfo[] files = dinfo.GetFiles("*.jpg");
foreach (FileInfo file in files)
{
listbox.Items.Add(file.Name);
}
}
private void listbox_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = "";
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
st = @"C:\abcd\"+listbox.SelectedItem.ToString();
label1.Text = st;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
img = new Bitmap(st);
// pictureBox1.ClientSize = new Size(xSize, ySize);
pictureBox1.Image = (Image)img;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
int borderWidth = 60;
Image img = Image.FromFile(st);
var borderColor = Color.White;
var newSize = new Size(
img.Width + borderWidth * 2,
img.Height + borderWidth * 2);
var imaag = new Bitmap(newSize.Width, newSize.Height);
var g = Graphics.FromImage(imaag);
g.Clear(borderColor);
g.DrawImage(img, new Point(borderWidth, borderWidth));
Font font = new Font("Times New Roman", 14.0f);
Point pt = new Point((imaag.Width / 5), (imaag.Height) - 50);
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawString(textBox1.Text, font, Brushes.Black, pt);
imaag.Save(@"d:\abcd\" + listbox.SelectedItem.ToString(), imaag.RawFormat);
}
catch (Exception exx)
{
MessageBox.Show("error");
}
}
}
}
No comments:
Post a Comment