保存为jpg
CString strFileName; //如果用户没有指定文件扩展名,则为其添加一个
CString strExtension,path;
CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
HBITMAP hbitmap = CreateCompatibleBitmap(dc, rect.right - rect.left, rect.bottom - rect.top);
HDC hdc = CreateCompatibleDC(dc); //创建兼容DC,以便将图像保存为不同的格式
HBITMAP hOldMap = (HBITMAP)SelectObject(hdc, hbitmap);
BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, dc, 0, 0, SRCCOPY);
CImage ig;
ig.Attach(hbitmap);
CFileDialog dlg(NULL, _T(".jpg"), _T("paint.jpg"), NULL);
dlg.DoModal();
strFileName = dlg.m_ofn.lpstrFile;
path = strFileName;
ig.Save(path);
ig.Detach();
MessageBox(_T("图像保存成功"), _T("提示"));
矩阵运算
//矩阵求逆
int MatrixInv(int n, double *a)
{
int *is, *js, i, j, k, l, u, v;
double d, p;
is = (int *)malloc(n * sizeof(int));
js = (int *)malloc(n * sizeof(int));
for (k = 0; k <= n - 1; k++)
{
d = 0.0;
for (i = k; i <= n - 1; i++)
for (j = k; j <= n - 1; j++)
{
l = i*n + j; p = fabs(a[l]);
if (p>d) { d = p; is[k] = i; js[k] = j; }
}
if (d + 1.0 == 1.0)
{
free(is); free(js); printf("err**not inv\n");
return(0);
}
if (is[k] != k)
for (j = 0; j <= n - 1; j++)
{
u = k*n + j; v = is[k] * n + j;
p = a[u]; a[u] = a[v]; a[v] = p;
}
if (js[k] != k)
for (i = 0; i <= n - 1; i++)
{
u = i*n + k; v = i*n + js[k];
p = a[u]; a[u] = a[v]; a[v] = p;
}
l = k*n + k;
a[l] = 1.0 / a[l];
for (j = 0; j <= n - 1; j++)
if (j != k)
{
u = k*n + j; a[u] = a[u] * a[l];
}
for (i = 0; i <= n - 1; i++)
if (i != k)
for (j = 0; j <= n - 1; j++)
if (j != k)
{
u = i*n + j;
a[u] = a[u] - a[i*n + k] * a[k*n + j];
}
for (i = 0; i <= n - 1; i++)
if (i != k)
{
u = i*n + k; a[u] = -a[u] * a[l];
}
}
for (k = n - 1; k >= 0; k--)
{
if (js[k] != k)
for (j = 0; j <= n - 1; j++)
{
u = k*n + j; v = js[k] * n + j;
p = a[u]; a[u] = a[v]; a[v] = p;
}
if (is[k] != k)
for (i = 0; i <= n - 1; i++)
{
u = i*n + k; v = i*n + is[k];
p = a[u]; a[u] = a[v]; a[v] = p;
}
}
free(is); free(js);
return(1);
}
//矩阵求积
void MatrixMul(double *a, double *b, int m, int n, int k, double *c)
{
int i,j,l,u;
for (i=0; i<=m-1; i++)
for (j=0; j<=k-1; j++)
{ u=i*k+j; c[u]=0.0;
for (l=0; l<=n-1; l++)
c[u]=c[u]+a[i*n+l]*b[l*k+j];
}
return;
}
//矩阵转置
void MatrixTra(int m, int n, double *A, double *AT)
{
int i, j;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
AT[j * m + i] = A[i * n + j];
}
//矩阵求和
void MatrixSum(int Am, int An, int Bm, int Bn, double *A, double *B, double *R)
{
int r = Am;
int c = An;
int n = r * c, i;
if (Am != Bm || An != Bn) {
printf("[matrix_sum] Error: mismatched dimensions\n");
return;
}
for (i = 0; i < n; i++) {
R[i] = A[i] + B[i];
}
}
//矩阵求差 R = A - B
void MatrixDiff(int Am, int An, int Bm, int Bn, double *A, double *B, double *R)
{
int r = Am;
int c = An;
int n = r * c, i;
if (Am != Bm || An != Bn) {
printf("[matrix_sum] Error: mismatched dimensions\n");
return;
}
for (i = 0; i < n; i++) {
R[i] = A[i] - B[i];
}
}
dxf
void Chart::LineDXF(FILE *fp,double x, double y, double x1, double y1)//刻度线
{
fprintf(fp, "0 \nLINE\n");
fprintf(fp, "8 \n0\n");
fprintf(fp, "62 \n1\n");
fprintf(fp, "10 \n%f\n20 \n%f\n11 \n%f\n21 \n%f\n",
x,y,x1,y1);
}
void Chart::CircleDXF(FILE *fp,double x,double y, double radius)//圆盘
{
fprintf(fp, "0 \nCIRCLE\n");
fprintf(fp, "8 \n0\n");
fprintf(fp, "62 \n1\n");
fprintf(fp, "10 \n%f\n20 \n%f\n40 \n%f\n",
x, y, radius);//圆心和半径
}
void Chart::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CDialogEx::OnOK();
FILE *fp;
fp = fopen("save.dxf", "w");
if (fp == NULL)
{
printf("Can not open this file !\n");
return;
}
fprintf(fp, "0\nSECTION\n");
fprintf(fp, "2\nENTITIES\n");
for (int i = 0; i < sou.p_data.pt2.size(); i++)
{
CircleDXF(fp, (-sou.p_data.pt2[i].old_x - 1950000) / 31.25 + 120 , 540 - (sou.p_data.pt2[i].old_y - 4480000) / 31.25 , 10);
}
LineDXF(fp, 120, 10,120,540);
LineDXF(fp, 120, 540, 720, 540);
LineDXF(fp, 117, 13, 120, 10);
LineDXF(fp, 120, 10, 123, 13);
LineDXF(fp, 717, 537, 720, 540);
LineDXF(fp, 720, 540, 717, 543);
for (int i = 0; i < 8; i++)
{
LineDXF(fp, 120 + 80 * i, 540, 120 + 80 * i, 530);
}
for (int i = 0; i < 7; i++)
{
LineDXF(fp, 120, 540 - 80 * i, 130, 540 - 80 * i);
}
fprintf(fp, "0 \nENDSEC\n");
fprintf(fp, "0 \nEOF");
fclose(fp);
MessageBox(_T("散点图保存成功(.dxf)"), _T("提示"));
}
保存txt
CString str(_T(""));
GetDlgItemText(IDC_EDIT1, str);
try
{
CFile fp;
fp.Open(_T("坐标转化计算报告.txt"), CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate, NULL);
int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
char *line = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, str, -1, line, len, NULL, NULL);
fp.Write(line, strlen(line));
fp.Close();
MessageBox(_T("计算报告保存成功"), _T("提示"), MB_ICONINFORMATION);
}
catch (CFileException*e)
{
e->ReportError();
e->Delete();
}
#include
#pragma warning(disable:4995)
CDaoDatabase m_daoDB;
CString strDB, str1;
CFileDialog dlgDB(FALSE, _T(".mdb"), _T("TIN.mdb"), NULL);
if (IDOK == dlgDB.DoModal())
{
strDB = dlgDB.m_ofn.lpstrFile;
}
//strDB = _T("TIN.mdb");
str1 = _T("CREATE TABLE 计算报告(ID AUTOINCREMENT PRIMARY KEY,1 VARCHAR(20),2 VARCHAR(20),3 VARCHAR(20),4 VARCHAR(20),5 VARCHAR(20))");
m_daoDB.Create(strDB, dbLangGeneral, dbVersion40);//创建数据库;
m_daoDB.Open(strDB);//打开数据库;
m_daoDB.Execute(str1.GetBuffer());//执行SQL语句;
CString strSql;
CString str11 = _T("前20个三角形");
CString s1, s2, s3, s4, s5, s = _T("");
strSql.Empty();
strSql = L"insert into 计算报告(1,2,3,4,5) values('" + str11 + L"','" + _T("") + L"','" + _T("") + L"','" + _T("") + L"','" + _T("") + L"')";
m_daoDB.Execute(strSql.GetBuffer());
m_list.DeleteAllItems();
for (int i = 0; i < 7; i++)
{
m_list.DeleteColumn(i);
}
DWORD dw = m_list.GetExtendedStyle();
dw |= LVS_EX_FULLROWSELECT;
dw |= LVS_EX_GRIDLINES;
m_list.SetExtendedStyle(dw);
m_list.InsertColumn(0, _T(""), LVCFMT_CENTER, 120);
m_list.InsertColumn(1, _T("B"), LVCFMT_CENTER, 120);
m_list.InsertColumn(2, _T("L"), LVCFMT_CENTER, 120);
m_list.InsertColumn(3, _T("X"), LVCFMT_CENTER, 120);
m_list.InsertColumn(4, _T("Y"), LVCFMT_CENTER, 120);
for (int i = 0; i < (T.n - 5); i++)
{
CString id;
id = (T.p[i].Num).c_str();
m_list.InsertItem(5 + i, id, LVCFMT_CENTER);
CString d, m, s, str;
T.p[i].rad2angle(T.p[i].rad_B1);
d.Format(_T("%.0f"), T.p[i].dd);
m.Format(_T("%.0f"), T.p[i].mm);
s.Format(_T("%.4f"), T.p[i].ss);
str = d + _T("°") + m + _T("′") + s + _T("′′");
m_list.SetItemText(i, 1, str);