Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;
using System.Configuration;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Windows.Forms;
using Tela.OCLEVER.Common;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data.Odbc;
using System.Collections;
using System.Drawing.Imaging;
using System.Drawing;


namespace Tela.OCLEVER.Prepping.MCI
{
public partial class CCMDCNRenamingForm : Form
{
Database db = new Database();
string batchNo_1 = "";
string batchNo_2 = "";
string batchNo_3 = "";
string batchNo_4 = "";
string batchNo_5 = "";
string batchNo_6 = "";
string batchNo_7 = "";
string batchNo_9 = "";
string batchNo_8 = "";
string batchNo_10 = "";
string batchNo_11= "";
string batchNo_12 = "";
string batchNo_13 = "";
string batchNo_14 = "";
string batchNo_15 = "";
string batchNo_16 = "";
string batchNo_17 = "";
string batchNo_18 = "";
string batchNo_19 = "";
string batchNo_20 = "";
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
int cnt4 = 0;
int cnt5 = 0;
int cnt6 = 0;
int cnt7 = 0;
int cnt8 = 0; int cnt9 = 0; int cnt10 = 0; int cnt11 = 0; int cnt12 = 0; int cnt13 = 0; int cnt14 = 0; int cnt15 = 0; int cnt16 = 0; int cnt17 = 0; int cnt18 = 0; int cnt19 = 0; int cnt20 = 0;
string cnt1_ = "";
string cnt2_ = "";
string cnt3_ = "";
string cnt4_ = "";
string cnt5_ = "";
string cnt6_ = "";
string cnt7_ = "";
string cnt8_ = ""; string cnt9_ = ""; string cnt10_ = ""; string cnt11_ = ""; string cnt12_ = ""; string cnt13_ = ""; string cnt14_ = ""; string cnt15_ = ""; string cnt16_ = ""; string cnt17_ = ""; string cnt18_ = ""; string cnt19_ = ""; string cnt20_ = "";




DataTable dt = new DataTable();
string FilePath = "";
bool imagefound = false;
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^(([1-9])|(0[1-9])|(1[0-2]))(([0-9])|([0-2][0-9])|(3[0-1]))(([0-9][0-9])|([1-2][0,9][0-9][0-9]))$");
public CCMDCNRenamingForm()
{
InitializeComponent();
}



private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

string GETSR(int count)
{
string sr = "";



if (count <= 100)
{
sr = "1000" + count.ToString();
if (sr.Length==6)
{
sr = sr.Remove(2,1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length==7)
{
sr = sr.Remove(2,2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 100 && count <= 200)
{
sr = "2000" + (count - 100).ToString();

if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 200 && count <= 300)
{
sr = "3000" + (count - 200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 300 && count <= 400)
{
sr = "4000" + (count - 300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 400 && count <= 500)
{
sr = "5000" + (count - 400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 500 && count <= 600)
{
sr = "6000" + (count - 500).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}

else if (count > 600 && count <= 700)
{
sr = "7000" + (count - 600).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}


}

else if (count > 700 && count <= 800)
{
sr = "8000" + (count - 700).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 800 && count <= 900)
{
sr = "9000" + (count - 800).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(2, 1);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(2, 2);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 900 && count <= 1000)
{
sr = "10000" + (count - 900).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1000 && count <= 1100)
{
sr = "11000" + (count - 1000).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0,2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1100 && count <= 1200)
{
sr = "12000" + (count - 1100).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1200 && count <= 1300)
{
sr = "13000" + (count - 1200).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}
else if (count > 1300 && count <= 1400)
{
sr = "14000" + (count - 1300).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
}
else if (count > 1400 && count <= 1500)
{
sr = "15000" + (count - 1400).ToString();
if (sr.Length == 6)
{
sr = sr.Remove(0, 2);

//MessageBox.Show(sr);
//sr = sr.Remove(1);
return sr;//+ count.ToString();

}
else if (sr.Length == 7)
{
sr = sr.Remove(0, 3);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}
else if (sr.Length == 8)
{
sr = sr.Remove(0, 4);
//sr = sr.Remove(2);
return sr;//+ count.ToString();

}

}

return sr;
}

bool checkvaliddate(string date1)
{
string year = date1.Substring(0, 4);
string month = date1.Substring(4, 2);
string day = date1.Substring(6, 2);
date1 = month +day+ year;
bool flag = false;
if (regex.IsMatch(date1))
flag = true;
else
flag = false;

return flag;
}



void copyDirectory(string Src, string Dst)
{
string source = Src;
String[] Files;
if(Dst[Dst.Length-1]!=Path.DirectorySeparatorChar)
Dst+=Path.DirectorySeparatorChar;
if(!Directory.Exists(Dst))
Directory.CreateDirectory(Dst);
Files=Directory.GetFileSystemEntries(Src);
foreach(string Element in Files)
{
// Sub directories
if(Directory.Exists(Element))
copyDirectory(Element,Dst+Path.GetFileName(Element));
// Files in directory
else
File.Copy(Element, Path.Combine(Dst ,Path.GetFileName(Element)),true);
}

}

public void reset()
{
batchNo_1 = "";//,batchNo_1,batchNo_1,batchNo_1,batchNo_1 = "";
batchNo_2 = "";
batchNo_3 = "";
batchNo_4 = "";
batchNo_5 = "";
batchNo_6 = "";
batchNo_7 = "";
batchNo_8 = "";
batchNo_9 = "";
batchNo_10 = "";
batchNo_11 = "";
batchNo_12 = "";
batchNo_13 = "";
batchNo_14 = "";
batchNo_15 = "";
batchNo_16 = "";
batchNo_17 = "";
batchNo_18 = "";
batchNo_19 = "";
batchNo_20 = "";
cnt1 = 0;
cnt2 = 0;
cnt3 = 0;
cnt4 = 0;
cnt5 = 0;
cnt6 = 0;
cnt7 = 0;
cnt8 = 0;
cnt9 = 0;
cnt10 = 0;
cnt11 = 0;
cnt12 = 0;
cnt13 = 0;
cnt14 = 0;
cnt15 = 0;
cnt16 = 0;
cnt17 = 0;
cnt18 = 0;
cnt19 = 0;
cnt20 = 0;

cnt1_ = "";
cnt2_ = "";
cnt3_ = "";
cnt4_ = "";
cnt5_ = "";
cnt6_ = "";
cnt7_ = "";
cnt8_ = "";
cnt9_ = "";
cnt10_ = "";
cnt11_ = "";
cnt12_ = "";
cnt13_ = "";
cnt14_ = "";
cnt15_ = "";
cnt16_ = "";
cnt17_ = "";
cnt18_ = "";
cnt19_ = "";
cnt20_ = "";
}

private void btn_submit_Click(object sender, EventArgs e)
{


btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;
reset();
try
{
if (rdbadvanced.Checked == true)
{
if (cmbdpi.SelectedItem.ToString() == "---Select---" || cmbheight.SelectedItem.ToString() == "---Select---" || cmbwidth.SelectedItem.ToString() == "---Select---")
{
MessageBox.Show("Please select the advanced features correctly.", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;

}

}


if (comboBox1.Text != "--Select Process--")
{
if (txt_FolderPath.Text == "")
{
MessageBox.Show("Please Select the Folder", "Error ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
return;
}

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1H";
string p_ID = "185";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type = "CCM1U";
string p_ID = "78";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;

}
if (comboBox1.SelectedItem.ToString() == "HCFA EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOH";
string p_ID = "191";
RenameFunction(p_Type, p_ID);
return;

}

if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBNU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB Reprice" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBRU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB EOB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBOU";
string p_ID = "192";
RenameFunction(p_Type, p_ID);
return;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type = "SSBND";
string p_ID = "193";
RenameFunction(p_Type, p_ID);
return;
}


}
else
{
MessageBox.Show("Please Select Process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;
progressBar1.Visible = false;

}



}

public void RenameFunction(string ptype, string p_ID)
{
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
string[] GetBatchNames = Directory.GetDirectories(txt_FolderPath.Text);
string path = "";

if (Directory.Exists(txt_FolderPath.Text))
{
string Orignal = "";
Orignal = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Orignal_Images");

copyDirectory(txt_FolderPath.Text, Orignal);
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);

FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
if (Imagenames.Length > 0)
{

string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}



create_batch_HCFA(ptype,p_ID);

string source = txt_FolderPath.Text;
copyDirectory(Orignal, source);
Directory.Delete(Orignal, true);
MessageBox.Show("Operation is Completed.\nTotal - " + Imagenames.Length + " Image(s) Processed.\nCreated Batche(s) are - \n" + batchNo_1 + "" + cnt1_ + " \n" + batchNo_2 + "" + cnt2_ + " \n" + batchNo_3 + "" + cnt3_ + " \n" + batchNo_4 + "" + cnt4_ + " \n" + batchNo_5 + "" + cnt5_ + " \n" + batchNo_6 + "" + cnt6_ + " \n" + batchNo_7 + "" + cnt7_ + " \n" + batchNo_8 + "" + cnt8_ + " \n" + batchNo_9 + "" + cnt9_ + "\n" + batchNo_10 + "" + cnt10_ + "\n" + batchNo_11 + "" + cnt11_ + "\n" + batchNo_12 + "" + cnt12_ + "\n" + batchNo_13 + "" + cnt13_ + "\n" + batchNo_14 + "" + cnt14_ + "\n" + batchNo_15 + "" + cnt15_ + "", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
//comboBox1.SelectedText = ("--Select Process--");
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
return;
}
else
{
MessageBox.Show("There is no .tif Image in selected folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txt_FolderPath.Text = "";
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

progressBar1.Visible = false;
}
}

}

private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Enabled = false;

comboBox1.SelectedText = ("---Select---");
comboBox2.SelectedText = ("---Select---");
cmbheight.SelectedText = ("---Select---");
cmbdpi.SelectedText = ("---Select---");
cmbwidth.SelectedText = ("---Select---");


progressBar1.Value = 0;
progressBar1.Visible = false;


}



static Image FixedSize(Image imgPhoto, int Width, int Height,string file_name,int dpi)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;

nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(dpi, dpi);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
bmPhoto.Save(file_name);
grPhoto.Dispose();
return bmPhoto;
}


public void create_batch_HCFA(string processType, string pId)
{
DirectoryInfo BatchName = new DirectoryInfo(txt_FolderPath.Text);



FileInfo[] Imagenames = BatchName.GetFiles("*.tif", SearchOption.AllDirectories);
StringBuilder osb = new StringBuilder();
osb.AppendLine("DECLARE");
osb.AppendLine("vIMGID NUMBER;");
osb.Append("Begin ");
if (Imagenames.Length < 1500)
{



progressBar1.Value = 10;
progressBar1.Minimum = 0;
progressBar1.Maximum = Imagenames.Length;
for (int i = 0; i < Imagenames.Length; i++)
{

progressBar1.Value = i;

if (i < 100)
{

string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "001");
batchNo_1 = processType +"120118" + "001";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked==true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString())+1);
}

}
else
{
File.Move(source, Batch_Folder);

}



progressBar1.Visible = true;
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME,SCAN_DATE ) VALUES ( " + pId + ", '"+batchNo_1+"','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt1++;
cnt1_ = " - " + cnt1.ToString() + " Images.";


}
if (i >= 100 && i < 200)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "002");
batchNo_2 = processType +"120118" + "002";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;
if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
//File.Move(source, Batch_Folder);
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '"+batchNo_2+"','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt2++;
cnt2_ = " - " + cnt2.ToString() + " Images.";
}
if (i >= 200 && i < 300)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "003");
batchNo_3 = processType +"120118" + "003";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '"+batchNo_3+"','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt3++;
cnt3_ = " - " + cnt3.ToString() + " Images.";
}
if (i >= 300 && i < 400)
{
// progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_4 = processType +"120118" + "004";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "004");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '"+batchNo_4+"','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt4++;
cnt4_ = " - " + cnt4.ToString() + " Images.";
}
if (i >= 400 && i < 500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "005");
batchNo_5 = processType +"120118" + "005";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '"+batchNo_5+"','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt5++;
cnt5_ = " - " + cnt5.ToString() + " Images.";
}
if (i >= 500 && i < 600)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_6 = processType +"120118" + "006";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "006");

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '"+batchNo_6+"','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");

cnt6++;
cnt6_ = " - " + cnt6.ToString() + " Images.";
}
if (i >= 600 && i < 700)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), processType +"120118" + "007");
batchNo_7 = processType +"120118" + "007";
if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '"+batchNo_7+"' ,'" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt7++;
cnt7_ = " - " + cnt7.ToString() + " Images.";
}
if (i >= 700 && i < 800)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_8 = processType +"120118" + "008";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_8);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_8 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt8++;
cnt8_ = " - " + cnt8.ToString() + " Images.";

}
if (i >= 800 && i < 900)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;

string OutPutfileName = processType +"120118" + "00" + sr + ".tif"; // +
batchNo_9 = processType +"120118" + "009";
Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_9);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_9 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt9++;
cnt9_ = " - " + cnt9.ToString() + " Images.";

}
if (i >= 900 && i < 1000)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_10 = processType +"120118" + "010";
string OutPutfileName = batchNo_10 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_10);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_10 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt10++;
cnt10_ = " - " + cnt10.ToString() + " Images.";

}


if (i >= 1000 && i < 1100)
{
// progressBar1.Value = 60;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_11 = processType +"120118" + "011";
string OutPutfileName = batchNo_11 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_11);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_11 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt11++;
cnt11_ = " - " + cnt11.ToString() + " Images.";
}
if (i >= 1100 && i < 1200)
{
// progressBar1.Value = 90;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_12 = processType +"120118" + "012";
string OutPutfileName = batchNo_12 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_12);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}

osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_12 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt12++;
cnt12_ = " - " + cnt12.ToString() + " Images.";
}
if (i >= 1200 && i < 1300)
{
// progressBar1.Value = 100;
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_13 = processType +"120118" + "013";
string OutPutfileName = batchNo_13 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_13);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_13 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt13++;
cnt13_ = " - " + cnt13.ToString() + " Images.";
}
if (i >= 1300 && i < 1400)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_14 = processType +"120118" + "014";
string OutPutfileName = batchNo_14 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_14);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_14 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");
cnt14++;
cnt14_ = " - " + cnt14.ToString() + " Images.";
}
if (i >= 1400 && i < 1500)
{
string Batch_Folder = "";

string Temp = "";
Temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), Temp);

if (!Directory.Exists(Temp))
{
Directory.CreateDirectory(Temp);
}

int NumberofImages = Imagenames.Length;

string sr = GETSR(i + 1);
string source = Imagenames[i].DirectoryName + "\\" + Imagenames[i].Name;
batchNo_15 = processType +"120118" + "015";
string OutPutfileName = batchNo_15 + sr + ".tif"; // +

Batch_Folder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images"), batchNo_15);

if (!Directory.Exists(Batch_Folder))
{
Directory.CreateDirectory(Batch_Folder);
}

Batch_Folder += "\\" + OutPutfileName;

if (rdbadvanced.Checked == true)
{
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(source))
{
FixedSize(bmp, Convert.ToInt32(cmbwidth.SelectedItem.ToString()), Convert.ToInt32(cmbheight.SelectedItem.ToString()), Batch_Folder, Convert.ToInt32(cmbdpi.SelectedItem.ToString()) + 1);
}

}
else
{
File.Move(source, Batch_Folder);

}
osb.Append("INSERT INTO SPGDB.CCM_IMAGE_RENAME( PROCESS_ID, BATCHNO, OLD_IMAGENAME, NEW_IMAGENAME, SCAN_DATE ) VALUES ( " + pId + ", '" + batchNo_15 + "','" + Imagenames[i].ToString() + "' , '" + OutPutfileName + "', '" + DateTime.Now.ToString("dd-MMM-yy") + "' );\n");

cnt15++;
cnt15_ = " - " + cnt15.ToString() + " Images.";
}



}
osb.Append("End;");
db.InsertDeleteUpdate(osb.ToString());



}
else
{
MessageBox.Show("Image Should be less than 1500", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}

public void GenerateReport(string p_id_HCFA, string p_id_UB, string p_id_DENTAL, string PType)
{
string R_folder = "";

//if (p_id_HCFA != "" && p_id_UB == "" && p_id_DENTAL == "")
//{
// // p_id_UB = "," + p_id_UB + " ";

//}

//if (p_id_HCFA == "" && p_id_UB != "" && p_id_DENTAL == "")
//{
// // p_id_UB = "," + p_id_UB + " ";

//}
//if (p_id_HCFA == "" && p_id_UB == "" && p_id_DENTAL != "")
//{
// // p_id_DENTAL = "," + p_id_DENTAL + " ";

//}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL != "")
{
p_id_UB = "," + p_id_UB + " ";
p_id_DENTAL = "," + p_id_DENTAL + " ";
}
if (p_id_HCFA != "" && p_id_UB != "" && p_id_DENTAL == "")
{
p_id_UB = "," + p_id_UB + " ";

}







string query = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( " + p_id_HCFA + " " + p_id_UB + " " + p_id_DENTAL + ") AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '" + p_id_HCFA.Replace(",", "") + "' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,'MM/DD/YYYY')= '" + DateTime.Now.ToString("dd/MMM/yyyy") + "' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '" + p_id_UB.Replace(",", "") + "' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,'MM/DD/YYYY')= '" + DateTime.Now.ToString("dd/MMM/yyyy") + "' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '" + p_id_DENTAL.Replace(",", "") + "' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,'MM/DD/YYYY')= '" + DateTime.Now.ToString("dd/MMM/yyyy") + "' ) ORDER BY new_imagename ASC ";
string q2 = "SELECT OLD_IMAGENAME,NEW_IMAGENAME FROM CCM_IMAGE_RENAME WHERE PROCESS_ID IN ( 78 ) AND BATCHNO IN ( SELECT batchno FROM HCFA_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,'MM/DD/YYYY')= '05/Jan/2012' union SELECT batchno FROM UB_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '78' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,'MM/DD/YYYY')= '05/Jan/2012' union SELECT batchno FROM DEN_OUTPUT_UPLOAD_TSN WHERE PROCESS_ID= '' AND OUTPUT_UPLOADED_FLAG =1 and TO_DATE(OUTPUT_UPLOAD_DATE,'MM/DD/YYYY')= '05/Jan/2012' ) ORDER BY new_imagename ASC ";
DataTable dtb = new DataTable();
dtb = db.GetTable(q2);
if (dtb.Rows.Count > 0)
{
string DuplicateFolder = "";
DuplicateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Renamed_Images_Report");

if (!Directory.Exists(DuplicateFolder))
{
Directory.CreateDirectory(DuplicateFolder);
}
R_folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


if (File.Exists(DuplicateFolder + "\\" + PType + "_" +"120118" + "_DCN_Report.txt"))
{
File.Delete(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
}
FileInfo t = new FileInfo(DuplicateFolder + "\\"+PType+"_" +"120118" + "_DCN_Report.txt");
StreamWriter Tex = t.AppendText();
Tex.WriteLine("TCN Original_Name");
foreach (DataRow drPrintRow in dtb.Rows)
{
String str = drPrintRow["NEW_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "") + " " + drPrintRow["OLD_IMAGENAME"].ToString().Replace(".TIF", "").Replace(".tif", "");
Tex.WriteLine(str);
}

Tex.Close();
MessageBox.Show("Report is generated.\nFile name is - " + ""+PType+"_" +"120118" + "_DCN_Report.txt", "Image Renamer", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.DoEvents();

txt_FolderPath.Text = "";

Process.Start(DuplicateFolder);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;



}
else
{
MessageBox.Show("There is no batches to generate report for today's date. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
btn_submit.Enabled = true;
btn_Cancal.Enabled = true;
btn_report.Enabled = true;

}
}

private void btn_Cancal_Click(object sender, EventArgs e)
{
this.Close();
}

private void btn_report_Click(object sender, EventArgs e)
{
if (comboBox2.Text != "---Select---" && comboBox1.SelectedItem != null)
{

if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "CCM_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "CCM")
{
string p_Type_HCFA = "185";
string p_Type_UB = "78";
string p_Type_DENTAL = "";

string ptype = "CCM";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "HCFA" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "";
string p_Type_DENTAL = "";
string ptype = "SSB_HCFA";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;
}
if (comboBox1.SelectedItem.ToString() == "UB" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "192";
string p_Type_DENTAL = "";
string ptype = "SSB_UB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;

}
if (comboBox1.SelectedItem.ToString() == "Dental" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "";
string p_Type_UB = "";
string p_Type_DENTAL = "193";
string ptype = "SSB_DENTAL";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);
return;

}

if (comboBox1.SelectedItem.ToString() == "---Select---" && comboBox2.SelectedItem.ToString() == "SSB")
{
string p_Type_HCFA = "191";
string p_Type_UB = "192";
string p_Type_DENTAL = "193";
string ptype = "SSB";


GenerateReport(p_Type_HCFA, p_Type_UB, p_Type_DENTAL, ptype);

return;
}




}
else
{
MessageBox.Show("Please Select Correct Process Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

}
btn_submit.Enabled = false;
btn_Cancal.Enabled = false;
btn_report.Enabled = false;





}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedItem.ToString()=="CCM")
{
comboBox1.Items.Remove("HCFA Reprice");
comboBox1.Items.Remove("HCFA EOB");
comboBox1.Items.Remove("UB Reprice");
comboBox1.Items.Remove("UB EOB");
comboBox1.Items.Remove("Dental");
comboBox1.Refresh();


}
if (comboBox2.SelectedItem.ToString() == "SSB")
{
if (comboBox1.Items.Count == 3)
{
comboBox1.Items.Add("HCFA Reprice");
comboBox1.Items.Add("HCFA EOB");
comboBox1.Items.Add("UB Reprice");
comboBox1.Items.Add("UB EOB");
comboBox1.Items.Add("Dental");

}


}


}

private void button1_Click_1(object sender, EventArgs e)
{
FolderBrowserDialog f = new System.Windows.Forms.FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txt_FolderPath.Text = f.SelectedPath;
}
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = false;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Enabled = true;

}


}
}





--------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
using System.Web;
using System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
// {
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
// }
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

// values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator / denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator / denominator;

// now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes); // finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth / finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600); // now set the bitmap resolution

bmp.Save("C:\\images\\output.tif"); // save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width / (double)nWidth;
double nYFactor = (double)bTemp.Height / (double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
// {
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
// {
// height = (int)(height * img.HorizontalResolution / img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
// }
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
// {
// ici = ListICI;
// break;
// }
//}

//// Can't find the TIFF encoder
//if (ici == null) return;

//// Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

//// Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//try
//{ // Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch (Exception ex)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose(); // Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

// values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator / denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator / denominator;

//// now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height); // finally set the image property resolution
// bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300); // now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif"); // save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
// return bmPhoto;




// bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.Clear(Color.Black);
//// grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



// bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}


private void button3_Click(object sender, EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
// EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}
Posted

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Numeric;
using System.Linq;
using System.Web;
using System.Web;
using System.IO;




using System.Windows.Forms;

namespace demofortiff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}




private void button1_Click(object sender, EventArgs e)
{
//using (Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\FHM1201101250028.tif"))
//{
// using (Bitmap newBitmap = new Bitmap(bitmap))
// {
// newBitmap.SetResolution(300, 300);
// newBitmap.Save("C:\\images\\file300", System.Drawing.Imaging.ImageFormat.Tiff);
// }
//}

int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
System.Drawing.Imaging. PropertyItem piXRes = bmp.GetPropertyItem(400);
System.Drawing.Imaging.PropertyItem piYRes = bmp.GetPropertyItem(400);

// values are stored as a rational number - numerator/denominator pair
numerator = BitConverter.ToInt32(piXRes.Value, 0);
denominator = BitConverter.ToInt32(piXRes.Value, 4);
float xRes = numerator / denominator;

numerator = BitConverter.ToInt32(piYRes.Value, 0);
denominator = BitConverter.ToInt32(piYRes.Value, 4);
float yRes = numerator / denominator;

// now set the values
byte[] numeratorBytes = new byte[4];
byte[] denominatorBytes = new byte[4];

numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
denominatorBytes = BitConverter.GetBytes(1);

Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);

bmp.SetPropertyItem(piXRes); // finally set the image property resolution
bmp.SetPropertyItem(piYRes);

// double ratio = maxWidth / finalWidth;
// int maxHeight = (int)img1.Height * ratio;
bmp.GetThumbnailImage(7000, 7000, null, IntPtr.Zero);



FixedSize(bmp, 200, 200);

bmp.SetResolution(600, 600); // now set the bitmap resolution

bmp.Save("C:\\images\\output.tif"); // save the image
}


}
public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
Bitmap bTemp = (Bitmap)b.Clone();
b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

double nXFactor = (double)bTemp.Width / (double)nWidth;
double nYFactor = (double)bTemp.Height / (double)nHeight;

for (int x = 0; x < b.Width; ++x)
for (int y = 0; y < b.Height; ++y)
b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
(int)(Math.Floor(y * nYFactor))));

return b;
}

private void button2_Click(object sender, EventArgs e)
{
//using (Image img = Image.FromStream(memoryStream))
//{
// Guid id = img.FrameDimensionsList[0];
// System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(id);
// int totalFrame = img.GetFrameCount(dimension);
// for (int i = 0; i < totalFrame; i++)
// {
// img.SelectActiveFrame(dimension, i);

// Faxed documents will have an non-square pixel aspect ratio.
// If this is the case,adjust the height so that the
// resulting pixels are square.
// int width = img.Width;
// int height = img.Height;
// if (img.VerticalResolution < img.HorizontalResolution)
// {
// height = (int)(height * img.HorizontalResolution / img.VerticalResolution);
// }

// bitmaps.Add(new Bitmap(img, new Size(width, height)));
// }
//}

//ImageCodecInfo ici = null;
//ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders();
//foreach (ImageCodecInfo ListICI in Encoders)
//{
// if (ListICI.MimeType == "image/tiff")
// {
// ici = ListICI;
// break;
// }
//}

//// Can't find the TIFF encoder
//if (ici == null) return;

//// Set encoder to use no compression
//EncoderParameters ep = new EncoderParameters();
//ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);

//// Load a new image
//Bitmap TempImg = new Bitmap("C:\\images\\CCM_HB_20111228_0031901.tif");

//try
//{ // Attempt to save the image
// TempImg.Save("C:\\images\\CCM_HB_20111228_.tif", ici, ep);
//}
//catch (Exception ex)
//{
// MessageBox.Show("Error saving image: " + ex.Message);
//}

//TempImg.Dispose(); // Clean up
//ep.Dispose();

//Image tif = Image.FromFile("C:\\images\\CCM_HB_20111228_0031901.tif");
//float width = tif.PhysicalDimension.Width;
//float height = tif.PhysicalDimension.Height;


//float hresolution = tif.HorizontalResolution;
//float vresolution = tif.VerticalResolution;






//tif.Dispose();


//MessageBox.Show(width.ToString());



int numerator, denominator;

using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);

// values are stored as a rational number - numerator/denominator pair
//numerator = BitConverter.ToInt32(piXRes.Value, 0);
//denominator = BitConverter.ToInt32(piXRes.Value, 4);
//float xRes = numerator / denominator;

//numerator = BitConverter.ToInt32(piYRes.Value, 0);
//denominator = BitConverter.ToInt32(piYRes.Value, 4);
//float yRes = numerator / denominator;

//// now set the values
//byte[] numeratorBytes = new byte[4];
//byte[] denominatorBytes = new byte[4];

//numeratorBytes = BitConverter.GetBytes(600); // specify resolution in numerator
//denominatorBytes = BitConverter.GetBytes(1);

//Array.Copy(numeratorBytes, 0, piXRes.Value, 0, 4); // set the XResolution value
//Array.Copy(denominatorBytes, 0, piXRes.Value, 4, 4);

//Array.Copy(numeratorBytes, 0, piYRes.Value, 0, 4); // set the YResolution value
//Array.Copy(denominatorBytes, 0, piYRes.Value, 4, 4);
// float height = bmp.PhysicalDimension.Height;

//bmp.SetPropertyItem(height); // finally set the image property resolution
// bmp.SetPropertyItem(piYRes);







FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300); // now set the bitmap resolution

bmp.Save("C:\\images\\boutput12222.tif"); // save the image
}






}

static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height,PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300 ,300);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
//grPhoto.Dispose();
// return bmPhoto;




// bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

// Graphics grPhoto = Graphics.FromImage(bmPhoto);
// grPhoto.Clear(Color.Black);
//// grPhoto.InterpolationMode =System.Drawing.Image.InterpolationMode.HighQualityBicubic;

// grPhoto.DrawImage(imgPhoto, new Rectangle(sourceX, sourceY, sourceX, sourceY), new Rectangle(destX, destY, destWidth, destHeight), GraphicsUnit.Pixel);

//bmPhoto.SetResolution(300, 300);
//ImageFormat.Tiff
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);



// bmPhoto.Save("C:\\images\\output1211.tif", encoderInfo, encoderParams);
//grPhoto.Dispose();
return bmPhoto;
}

private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}


private void button3_Click(object sender, EventArgs e)
{

Bitmap bitmap = (Bitmap)Image.FromFile("C:\\images\\CCM_HB_20111228_0032801.tif");
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
string jay = "C:\\images\\boutput12350.tif";


Image tiff = Image.FromStream(byteStream);
ImageCodecInfo encoderInfo = GetEncoderInfo ("image/tiff");

EncoderParameters encoderParams = new EncoderParameters(2);
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = parameter;
parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
tiff.Save(jay, encoderInfo, encoderParams);
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
EncoderParameter CompressionEncodeParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
EncoderParams.Param[0] = CompressionEncodeParam;
EncoderParams.Param[1] = SaveEncodeParam;
tiff.SaveAdd(EncoderParams);
// EncoderParameter SaveEncodeParam = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.Flush);
//EncoderParams = new EncoderParameters(1);
//EncoderParams.Param[0] = SaveEncodeParam;
//tiff.SaveAdd(EncoderParams);







}



}
}
 
Share this answer
 
static Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2);
}

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
//bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
bmPhoto.SetResolution(300, 300);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the bitmap as a TIFF file with group IV compression.
EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
encoderParameters.Param[0] = encoderParameter;
bmPhoto.Save("C:\\images\\output1211.tif", imageCodecInfo, encoderParameters);

return bmPhoto;
}











private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}










using (Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\images\\QUOTE014.tif"))
{
// obtain the XResolution and YResolution TIFFTAG values
PropertyItem piXRes = bmp.GetPropertyItem(282);
PropertyItem piYRes = bmp.GetPropertyItem(283);


FixedSize(bmp, 2500, 3200);


bmp.SetResolution(300, 300); // now set the bitmap resolution


}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900