截图
作者:互联网
#include "me.hpp" void getBmp(double pos1[3], double pos2[3]); extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); double douP1[3] = { 500,0,0 }; double douP2[3] = { 0,500,0 }; getBmp(douP1, douP2); UF_terminate(); } extern int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); } //将图片复制到剪贴板 BOOL CopyBmp2Clipboard(LPCTSTR szFilePath) { BOOL bRet = FALSE; HBITMAP hBitmap = NULL; BOOL bClipboardOpened = FALSE; do { hBitmap = (HBITMAP)LoadImage(NULL, szFilePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (hBitmap == NULL) break; if (!OpenClipboard(NULL)) break; bClipboardOpened = TRUE; EmptyClipboard(); SetClipboardData(CF_BITMAP, hBitmap); bRet = TRUE; } while (0); if (bClipboardOpened) { CloseClipboard(); } if (hBitmap) { DeleteObject(hBitmap); hBitmap = NULL; } return bRet; } void getBmp(double pos1[3], double pos2[3]) { double PosXmin, PosXmax, PosYmin, PosYmax; UF_CSYS_map_point(UF_CSYS_WORK_COORDS, pos1, UF_CSYS_ROOT_WCS_COORDS, pos1); UF_CSYS_map_point(UF_CSYS_WORK_COORDS, pos1, UF_CSYS_ROOT_WCS_COORDS, pos2); tag_t view_work_tag = NULL_TAG; tag_t matrix_id = NULL_TAG, temp_wcs = NULL_TAG; char name[254]; double plane_matrix[9], plane_origin[3] = { 0.0,0.0,0.0 }; double Center[3]; double Scale; UF_VIEW_ask_work_view(&view_work_tag); UF_OBJ_ask_name(view_work_tag, name); uc6433(name, plane_matrix); UF_CSYS_create_matrix(plane_matrix, &matrix_id); UF_CSYS_create_temp_csys(plane_origin, matrix_id, &temp_wcs); UF_CSYS_set_wcs(temp_wcs); double xy_clip_bounds[4]; UF_VIEW_ask_current_xy_clip(view_work_tag, xy_clip_bounds); uc6430(name, Center, &Scale); UF_CSYS_map_point(UF_CSYS_WORK_COORDS, Center, UF_CSYS_ROOT_WCS_COORDS, Center); if (pos1[0]>pos2[0]) { PosXmin = pos2[0]; PosXmax = pos1[0]; } else { PosXmin = pos1[0]; PosXmax = pos2[0]; } if (pos1[1]>pos2[1]) { PosYmin = pos2[1]; PosYmax = pos1[1]; } else { PosYmin = pos1[1]; PosYmax = pos2[1]; } ////导出图片 int upper_left_corners[2]; int width, height; upper_left_corners[0] = 0; upper_left_corners[1] = 0; width = 0; height = 0; DWORD dwSize = 50; WCHAR temppath[50]; GetTempPath(dwSize, temppath); CString puch(temppath); puch = puch + "ugapi.bmp"; char bmp_path[256]; strcpy(bmp_path, CT2A(puch)); UF_DISP_create_framed_image(bmp_path, UF_DISP_BMP, UF_DISP_WHITE, upper_left_corners, width, height); FILE *fp = fopen(bmp_path, "rb"); //跳过位图文件头结构BITMAPFILEHEADER fseek(fp, sizeof(BITMAPFILEHEADER), 0); //定义位图信息头结构变量,读取位图信息头进内存,存放在变量head中 BITMAPINFOHEADER head; fread(&head, sizeof(BITMAPINFOHEADER), 1, fp); //获取图像宽、高、每像素所占位数等信息 int bmpWidth = head.biWidth; int bmpHeight = head.biHeight; fclose(fp);//关闭文件 upper_left_corners[0] = bmpWidth*(PosXmin - xy_clip_bounds[0] - Center[0]) / (2 * xy_clip_bounds[1]); upper_left_corners[1] = bmpHeight*(xy_clip_bounds[3] + Center[1] - PosYmax) / (2 * xy_clip_bounds[3]); width = bmpWidth*(PosXmax - PosXmin) / (2 * xy_clip_bounds[1]); height = bmpHeight*(PosYmax - PosYmin) / (2 * xy_clip_bounds[3]); UF_DISP_create_framed_image(bmp_path, UF_DISP_BMP, UF_DISP_WHITE, upper_left_corners, width, height); CopyBmp2Clipboard(puch); }
标签:截图,double,CSYS,xy,UF,pos2,pos1 来源: https://www.cnblogs.com/KMould/p/16388616.html