123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- // ImportPhoto.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ImportPhoto.h"
- #include "MyLock.h"
- #include "ZipTypeDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- ImportPhoto::ImportPhoto(CWnd* pParent ): CDialog(ImportPhoto::IDD, pParent)
- {
- m_mode = 0;
- m_pArray2 = NULL;
- m_pDesArray = NULL;
- m_exitcode = 0;
- m_bOverWrite = 1;
- m_bBeautifySkinFrom = 0;
- m_bOrigin = 0;
- m_bSaveUploadTask = 0;
- m_bCopyToLocal = 0;
- m_nOutputSize = 0;
- m_bOfmat = 0;
- m_nphototype = -1;
- m_bAddname = 0;
- beginno = -1;
- m_bautono = 1;
- }
- void ImportPhoto::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_PROGRESS1, m_progress);
- }
- BEGIN_MESSAGE_MAP(ImportPhoto, CDialog)
- ON_WM_CLOSE()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- void ImportPhoto::OnOK()
- {
- // TODO: Add extra validation here
- }
- void ImportPhoto::OnCancel()
- {
- // TODO: Add extra cleanup here
- }
- //----------------------------------------------------
- // remark by Jeff 2014.12.11 pm
- // 函数:GetFileNo
- // 描述:从订单文件夹中获取相片文件的最大编号值;
- // 参数:dir 订单文件夹;
- // 返回:返回订单文件夹中文件编号最大的值+1;
- //
- // 如果使用相片名来保存,就不需要这一步了;
- //----------------------------------------------------
- int ImportPhoto::GetFileNo(CString strOrderFolder)
- {
- if (m_bautono == 0)
- {
- int a = beginno;
- beginno++;
- return a;
- }
- CString path;
- CString path2;
- CString path3;
- CString path4;
- int begin = 1;
- CString temp;
- CStringArray array;
- // 1.查找订单文件夹下的所有文件夹,包括子文件夹下的文件夹;
- using namespace helper_coffs;
- ffsco o;
- o.dirs(1); // 子文件夹也查找;
- o.find(LPCSTR(strOrderFolder), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_dir();
- for (it = coo.begin(); coo.end() != it; it++)
- {
- temp = (*it).c_str();
- if (::FindArray(&array, temp) == -1)
- array.Add(temp);
- }
- // 2.查找出订单文件夹下最大编号值的相片名;
- BOOL bFind = 1;
- while (bFind)
- {
- bFind = 0;
- for (int i = 0; i < array.GetSize(); i++)
- {
- strOrderFolder = array.ElementAt(i);
- path.Format("%s%03d.jpg", strOrderFolder, begin);
- path2.Format("%s%03d.raw", strOrderFolder, begin);
- path3.Format("%s%03d.cr2", strOrderFolder, begin);
- path4.Format("%s%03d.NEF", strOrderFolder, begin);
- //while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))PathFileExists
- while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))
- {
- begin++;
- path.Format("%s%03d.jpg", strOrderFolder, begin);
- path2.Format("%s%03d.raw", strOrderFolder, begin);
- path3.Format("%s%03d.cr2", strOrderFolder, begin);
- path4.Format("%s%03d.NEF", strOrderFolder, begin);
- bFind = 1;
- }
- }
- }
- // 3.返回找到的最大编号值+1;
- beginno = begin + 1;
- return begin;
- }
- void FilterFileName(CString &str)
- {
- //printf("Jeff:保存目录old:%s\n\n",str);
- ///\:*?"<>|
- str.Replace("/", "");
- str.Replace("\\", "");
- str.Replace(":", "");
- str.Replace("*", "");
- str.Replace("?", "");
- str.Replace("\"", "");
- str.Replace("<", "");
- str.Replace(">", "");
- str.Replace("|", "");
- //printf("Jeff:保存目录last:%s\n\n",str);
- }
- UINT ImportPhotoThread(LPVOID lpParameter)
- {
- ImportPhoto *pThis = (ImportPhoto*)lpParameter;
- pThis->m_progress.SetRange(0, pThis->m_pArray->GetSize());
-
- CString filename, filename2;
- CString temp;
- int pos;
- BOOL bNeedGet;
- CString temp2;
- int fileno;
- if (pThis->m_pArray2) // m_pArray2:产品名;
- {
- if (pThis->m_bAddname) // 相片名包含产品名:不生成产品文件夹;
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- filename = pThis->m_pArray->ElementAt(i);
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.Find(".");
- temp = temp.Left(pos);
- temp += "(" + pThis->m_name + ",";
- temp2 = pThis->m_pArray2->ElementAt(i) + ").jpg";
- FilterFileName(temp2);
- // Jeff.add:拷贝文件失败,未做处理,最起码要日志记录失败原因;
- ::CopyFile(filename, pThis->m_savepath + temp + temp2, pThis->m_bOverWrite == 0);
- pThis->m_progress.SetPos(i + 1);
- }
- }
- else // 相片名不包含产品,另外生成产品文件夹。
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- filename = pThis->m_pArray->ElementAt(i);
- filename2 = pThis->m_pArray2->ElementAt(i);
- pos = filename2.Find(";");
- while (pos != -1)
- {
- temp = filename2.Left(pos);
- FilterFileName(temp);
- filename2 = filename2.Right(filename2.GetLength() - pos - 1);
- pos = filename2.Find(";");
- // Jeff:生成产品文件夹,然后将与之关联的所有相片都复制一份.
- ::CreateDirectory(pThis->m_savepath + temp, NULL);
- pThis->MyCopyFile(filename, pThis->m_savepath + temp + filename.Right(filename.GetLength() - filename.ReverseFind('\\')), pThis->m_bOverWrite == 0);
- temp2 = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- int pos2 = temp2.Find(".");
- if (pos2 != -1)
- {
- temp2 = temp2.Left(pos2);
- CString filename2;
- }
- }
- temp = filename2;
- FilterFileName(temp);
- ::CreateDirectory(pThis->m_savepath + temp, NULL);
- pThis->MyCopyFile(filename, pThis->m_savepath + temp + filename.Right(filename.GetLength() - filename.ReverseFind('\\')), pThis->m_bOverWrite == 0);
- temp2 = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp2.Find(".");
- if (pos != -1)
- {
- temp2 = temp2.Left(pos);
- }
- pThis->m_progress.SetPos(i + 1);
- }
- }
- }
- else if (pThis->m_pDesArray)
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- filename = pThis->m_pArray->ElementAt(i);
- if (pThis->m_mode == 2)
- {
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.Find(".");
- bNeedGet = 1;
- if (bNeedGet)// && (g_serverbak!="localserver"))
- filename2.Format("%s%03d.jpg", pThis->m_savepath, pThis->GetFileNo(pThis->m_calnopath));
- else
- filename2.Format("%s%s.jpg", pThis->m_savepath, temp);
- pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
- }
- else
- pThis->MyCopyFile(filename, pThis->m_pDesArray->ElementAt(i), pThis->m_bOverWrite == 0);
- pThis->m_progress.SetPos(i + 1);
- }
- }
- //-----------------------------------------------------------------
- //-----------------------------------------------------------------
- // 1.拍照导入原片;
- // 2.初修导出原片;
- // 3.初修导入修好的修片;
- // 4.初修导出修好的片;
- // 5.选片缓存到本机;
- else
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- // filename源文件的文件名;
- filename = pThis->m_pArray->ElementAt(i);
- // 在导入原片时,该值m_mode=2;
- // 在初修导出原片时,该值m_mode=1;
- // 选片缓存到梧桐时,m_mode=1;
- if (pThis->m_mode == 2)
- {
- // 得到相片的后缀名ext;
- CString ext = filename.Right(filename.GetLength() - filename.ReverseFind('.') - 1);
- if (0)//g_serverbak=="localserver")
- {
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- filename2.Format("%s%s", pThis->m_savepath, temp);
- }
- else
- {
- // 在导入原片时,m_calnopath其实就是订单文件夹;
- // 从订单文件夹里获取最大的相片名编号值+1;
- // 这一步过于蛋痛!
- fileno = pThis->GetFileNo(pThis->m_calnopath);
- // 用最大编号+1重新命名新导入的相片名;
- filename2.Format("%s%03d.%s", pThis->m_savepath, fileno, ext);
- }
- // 新文件名:filename2,原文件名filename;boverwrite==0表示新文件名存在就覆盖;
- pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
- }
- else
- {
- if (pThis->m_bBeautifySkinFrom)//修片导入
- {
- temp = pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.ReverseFind('.');
- if (pos == -1)continue;
- temp = temp.Left(pos);
- pos = 0;
- filename2.Format("%s.jpg", temp);
- pos = 2;
- while (::PathFileExists(filename2))
- {
- filename2.Format("%s-%d.jpg", temp, pos);
- pos++;
- }
- pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
- }
- else
- {
- if (pThis->m_bOrigin)//原片导出
- {
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.Find(".");
- if (pos == -1)continue;
- temp = temp.Left(pos);
- pThis->MyCopyFile(filename, pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1), pThis->m_bOverWrite == 0);
- }
- else
- pThis->MyCopyFile(filename, pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1), pThis->m_bOverWrite == 0);
- }
- }
- pThis->m_progress.SetPos(i + 1);
- }
- }
- pThis->PostMessage(WM_CLOSE, 0, 0);
- return 1;
- }
- BOOL ImportPhoto::OnInitDialog()
- {
- CDialog::OnInitDialog();
- #if JEFF_TEST_OFF
- // Jeff:判断目标路径是否合法;
- if ( IsDirectoryLegitimate(m_name) == FALSE)
- {
- AfxMessageBox("目标路径包含创建目录时的非法目录字符'/ \\ : * ? \" < > |',请修改后重新操作!");
- return FALSE;
- }
- #endif
- if (m_bCopyToLocal)
- SetDlgItemText(IDC_STATIC1, "客照缓存中, 请稍候...");
- else if (m_mode == 1)
- SetDlgItemText(IDC_STATIC1, "正在导出客照, 请稍候...");
- #if JEFF_TEST_OFF
- HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ImprotOrExportImageThread, (LPVOID)this, 0, NULL);
- CloseHandle(hThread);
- #endif
- if (beginno != -1 && beginno != 0)
- {
- m_bautono = 0;
- }
- AfxBeginThread((AFX_THREADPROC)ImportPhotoThread, (LPVOID)this);
- return TRUE;
- }
- void SaveTaskPath(CString pathname)
- {
- return;
- CString path = g_path1 + "\\taskpath.dat";
- CStringArray array;
- CFile fp;
- if (::PathFileExists(path))
- {
- try
- {
- int trycount = 5;
- while (1)
- {
- if (fp.Open(path, CFile::modeRead | CFile::shareExclusive))break;
- fp.Close();
- trycount--;
- if (trycount == 0)break;
- ::Sleep(1000);
- }
- if (trycount == 0)
- {
- if (::PathFileExists(path))return;
- }
- CArchive ar(&fp, CArchive::load);
- array.Serialize(ar);
- fp.Close();
- }
- catch (...)
- {
- fp.Close();
- // AfxMessageBox("读异常");
- }
- }
- array.Add(pathname);
- try
- {
- int trycount = 5;
- while (1)
- {
- if (fp.Open(path, CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive))break;
- fp.Close();
- trycount--;
- if (trycount == 0)break;
- ::Sleep(1000);
- }
- if (trycount == 0)
- {
- // AfxMessageBox("打开失败2");
- return;
- }
- CArchive ar(&fp, CArchive::store);
- array.Serialize(ar);
- ar.Close();
- fp.Close();
- }
- catch (...)
- {
- // AfxMessageBox("写异常");
- fp.Close();
- }
- }
- void ImportPhoto::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- if (m_nphototype < 0 || m_nphototype>3)
- {
- CDialog::OnOK();
- return;
- }
- if (m_uploadtaskarray.GetSize() <= 10)
- {
- CDialog::OnOK();
- return;
- }
- #ifdef ENTERPRISE_VERSION
- if (m_bSaveUploadTask)
- {
- CString m_rule = g_cominfoarraylocal.ElementAt(0).ElementAt(116);
- //printf("Jeff:m_rule: %s\n", m_rule);
- CString m_header, m_left, m_right, m_currule;
- CStringArray rulearray;
- if (m_nphototype == 0)
- {
- m_header = "type0@:";
- }
- else if (m_nphototype == 1)
- {
- m_header = "type1@:";
- }
- else if (m_nphototype == 2)
- {
- m_header = "type2@:";
- }
- else if (m_nphototype == 3)
- {
- m_header = "type3@:";
- }
- //printf("Jeff:m_header: %s\n", m_header);
- int pos = m_rule.Find(m_header);
- if (pos != -1)
- {
- m_left = m_rule.Left(pos);
- //printf("Jeff:m_left: %s\n", m_left);
- m_rule = m_rule.Right(m_rule.GetLength() - pos);
- m_rule.Delete(0, m_header.GetLength());
- //printf("Jeff:m_rule: %s\n", m_rule);
- pos = m_rule.Find("@:");
- if (pos != -1)
- {
- m_right = m_rule.Right(m_rule.GetLength() - pos + 5);
- m_rule = m_rule.Left(pos - 5);
- //printf("Jeff:m_right: %s # m_rule : %s\n", m_right, m_rule);
- }
- m_currule = m_rule;
- m_rule.Empty();
- m_currule.TrimLeft("%$");
- m_currule.TrimRight("%$");
- //printf("Jeff:m_currule: %s # m_rule : %s\n", m_currule, m_rule);
- if (m_currule.Find("%$") != -1)
- {
- pos = m_currule.Find("%$");
- while (pos != -1)
- {
- if (m_currule.Left(pos) != "")rulearray.Add(m_currule.Left(pos));
- m_currule = m_currule.Right(m_currule.GetLength() - pos - 2);
- pos = m_currule.Find("%$");
- //printf("Jeff:m_currule: %s\n", m_currule);
- }
- }
- if (m_currule != "")rulearray.Add(m_currule);
- }
- for (int i = 0; i < rulearray.GetSize(); i++)
- {
- m_currule = rulearray.ElementAt(i);
- pos = m_currule.Find("->");
- if (pos == -1)continue;
- m_left = m_currule.Left(pos);
- m_right = m_currule.Right(m_currule.GetLength() - pos - 2);
- CString curdomain, curdomain2;
- //printf("Jeff:m_branch: %s\n", m_branch);
- if (m_branch != "")
- {
- curdomain = GetDomainFromBranch(m_branch);
- curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
- }
- else if (g_branchname != "")
- {
- curdomain = GetDomainFromBranch(g_branchname);
- curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
- }
- else
- {
- curdomain = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
- curdomain2 = curdomain;
- }
- //printf("Jeff:curdomain: %s # curdomain2 : %s\n", curdomain, curdomain2);
- CString domainleft = GetDomainFromBranch(m_left);
- if (curdomain != domainleft)
- {
- continue;
- }
- CString domainright = GetDomainFromBranch(m_right);
- //printf("Jeff:domainright: %s\n", domainright);
- if (domainleft.Find(".ly.com") == -1 || domainright.Find(".ly.com") == -1)
- {
- continue;
- }
- if (curdomain2 == domainright)
- {
- continue;
- }
- MyLock lock("uploadtaskaccess");
- //printf("Jeff:domainright: %s # domainleft : %s # m_sel : %s\n", domainright, domainleft, m_sel);
- m_uploadtaskarray.SetAt(1, domainright);//目的地
- m_uploadtaskarray.SetAt(2, domainleft);//文件夹加上域名
- m_uploadtaskarray.SetAt(3, m_sel);
- CFile fp;
- CString pathdir = m_savepath + "uploadtask";
- //printf("Jeff:pathdir: %s\n", pathdir);
- if (m_id != "")
- {
- int pos = pathdir.Find(m_id);
- pos += m_id.GetLength();
- int pos2 = pathdir.ReverseFind('\\');
- pathdir = pathdir.Left(pos) + pathdir.Right(pathdir.GetLength() - pos2);
- }
- CString path;
- int taskpos = 1;
- path.Format("%s%d.dat", pathdir, taskpos);
- CString dir = path.Left(path.ReverseFind('\\') + 1);
- pathdir = g_path1 + "\\上传任务\\";
- //printf("Jeff:pathdir: %s\n", pathdir);
- ::CreateDirectory(pathdir, NULL);
- path.Format("%s%d.dat", pathdir, taskpos);
- while (PathFileExists(path))
- {
- taskpos++;
- path.Format("%s%d.dat", pathdir, taskpos);
- printf("Jeff:path: %s\n", path);
- }
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- CArchive ar(&fp, CArchive::store);
- //printf("Jeff:dir: %s\n", dir);
- m_uploadtaskarray.SetAt(4, dir);
- m_uploadtaskarray.Serialize(ar);
- ar.Close();
- fp.Close();
- // SaveTaskPath(path);
- }
- }
- #endif
- // CString ss;
- //ss.Format ("cc:%d", g_filecount);MessageBox(ss);m_fp.Close ();
- CDialog::OnOK();
- }
- extern void SaveImageToFile(Image *img, CString path);
- void ImportPhoto::MyCopyFile(CString file1, CString file2, BOOL bOverWrite)
- {
- if (::PathFileExists(file1) == 0)
- {
- return;
- }
- if (m_bOfmat)
- {
- CString file1bak = file1;
- CString file2bak = file2;
- file1bak = file1bak.Left(file1bak.GetLength() - 3);
- file2bak = file2bak.Left(file2bak.GetLength() - 3);
- file1bak += "jpg";
- file2bak += "jpg";
- CString src = file1bak;
- CString des = file2bak;
- src.Replace(".jpg", ".raw");
- des.Replace(".jpg", ".raw");
- ::CopyFile(src, des, bOverWrite);
- src = file1bak;
- des = file2bak;
- src.Replace(".jpg", ".nef");
- des.Replace(".jpg", ".nef");
- ::CopyFile(src, des, bOverWrite);
- src = file1bak;
- des = file2bak;
- src.Replace(".jpg", ".cr2");
- des.Replace(".jpg", ".cr2");
- ::CopyFile(src, des, bOverWrite);
- }
- if (m_nphototype == 0 || m_nphototype == 1 || m_nphototype == 2 || m_nphototype == 3)
- {
- CString str = file2;
- CString spath = str.Left(str.ReverseFind('\\') + 1);
- CString mpath = spath;
- spath += "s";
- spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
- mpath += "m";
- mpath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
- ::DeleteFile(spath); // 删除s小图;
- ::DeleteFile(mpath); // 删除m小图;
- }
- if (m_nOutputSize)
- {
- file1.MakeLower();
- if (file1.Right(3) == "jpg")
- {
- Image *img = NULL;
- ::LoadImageFromBuf(&img, file1);
- if (img == NULL)
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!");
- }
- }
- else if (img->GetWidth() == 0)
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!");
- }
- }
- else
- {
- int newsize = m_nOutputSize;
- if (img->GetWidth() > newsize || img->GetHeight() > newsize)
- {
- CRect rc(0, 0, newsize, newsize);
- RectFitDes(img->GetWidth(), img->GetHeight(), rc);
- Image *simg = img->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
- Graphics graphic(simg);//防止GetThumbnailImage影响质量
- graphic.DrawImage(img, 0, 0, simg->GetWidth(), simg->GetHeight());
- delete img;
- ::SaveImageToFile(simg, file2);
- delete simg;
- }
- else
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!");
- }
- }
- }
- }
- else
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!");
- }
- }
- }
- else
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!!");
- }
- //
- if (m_bCopyToLocal)//选片缓存
- {
- CString path = file2;
- CString spath = path.Left(path.ReverseFind('\\') + 1);
- spath += "s";
- // CString temp=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
- spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- //if(!PathFileExists (spath))
- {
- Image *pImg = NULL;
- ::LoadImageFromBuf(&pImg, path);
- if (pImg == NULL)return;
- if (pImg->GetWidth() == 0)return;
- CRect rc(0, 0, 100, 90);
- RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
- Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
- if (simg == NULL)return;
- Graphics graphic(simg);//防止GetThumbnailImage影响质量
- graphic.Clear(Color(255, 255, 255, 255));
- graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight());
- ///////////////////////////////
- UINT totalBufferSize;
- UINT numProperties;
- pImg->GetPropertySize(&totalBufferSize, &numProperties);
- // Allocate the buffer that will receive the property items.
- PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
- // Fill the buffer.
- pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
- // Print the id data member of each property item.
- for (UINT j = 0; j < numProperties; ++j)
- {
- if (PropertyTagOrientation == pAllItems[j].id)
- {
- short* ptrLong = (short*)(pAllItems[j].value);
- int ret = (int)*ptrLong;
- // CString str;
- // str.Format ("%d", ret);
- // AfxMessageBox(str);
- if (ret == 8)
- {
- simg->RotateFlip(Rotate270FlipNone);
- }
- else if (ret == 6)
- {
- simg->RotateFlip(Rotate90FlipNone);
- }
- break;
- }
- }
- free(pAllItems);
- ///////////////////////////////
- ::SaveImageToFile(simg, spath);
- delete simg;
- delete pImg;
- }
- }//选片缓存
- }
- file2.MakeLower();
- if (m_mode != 1 && file2.Right(3) == "jpg")
- {
- CString path = file2.Left(file2.ReverseFind('\\'));
- path.TrimRight("\\"); path += "\\";
- path += "modifytime";
- CStdioFile fp;
- if (::PathFileExists(path))
- {
- fp.Open(path, CFile::modeWrite);
- fp.WriteString(g_date);
- fp.Close();
- }
- else
- {
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.WriteString(g_date);
- fp.Close();
- }
- }
- #ifdef ENTERPRISE_VERSION
- if (m_bSaveUploadTask)
- {
- if (m_id != "")
- {
- if (file2.Right(3) == "jpg")
- {
- int pos = file2.Find(m_id);
- pos += m_id.GetLength();
- int pos2 = file2.ReverseFind('\\');
- // Jeff:获取景点;
- CString jd;
- if (pos2 > pos)
- {
- jd = file2.Mid(pos + 1, pos2 - pos - 1);
- }
- CString task;
- if (jd != "")
- task = jd + "\\" + file2.Right(file2.GetLength() - pos2 - 1);
- else
- task = file2.Right(file2.GetLength() - pos2 - 1);
- m_uploadtaskarray.Add(task);
- m_uploadtaskarray.Add("");
- }
- }
- else
- {
- if (file2.Right(3) == "jpg")
- {
- m_uploadtaskarray.Add(file2.Right(file2.GetLength() - m_savepath.GetLength()));
- m_uploadtaskarray.Add("");
- }
- }
- }
- #endif
- }
- //*
- unsigned int WINAPI ImportPhoto::ImprotOrExportImageThread(LPVOID lp)
- {
- ImportPhoto *pThis = (ImportPhoto*)lp;
- if ( pThis->m_bImportImage )
- {
- // 初始化工作,并将导入标识写入数据库中;
- switch ( pThis->m_ImportOfImageType )
- {
- case ImageType_Original:
- break;
- case ImageType_Early:
- break;
- case ImageType_Further:
- break;
- case ImageType_Design:
- break;
- default:
- break;
- }
- // 实参校验;
- if ( pThis->m_pArray->GetSize() > 0 && lyfzCreateDirectory(pThis->m_savepath))
- lyfzImportImage(pThis->m_savepath, *(pThis->m_pArray));
- }
- else
- {
- // 初始化工作;
- switch (pThis->m_ExportOfImageType)
- {
- case ImageType_Original:
- break;
- case ImageType_Early:
- break;
- case ImageType_Further:
- break;
- case ImageType_Design:
- default:
- break;
- }
- }
- return 0;
- }
|