ubuntu对指定区域截图

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/surserrr/article/details/88950584

ubuntu有自带的截图工具,分三种类型:全屏、当前活动窗口、自定义区域。

设置好自定义区域的截图快捷键就可以使用,系统设置-->键盘-->快捷键-->截图-->对选区截图,按习惯设置了Ctrl+Alt+A。完成后就可以使用快捷键截图了!

展开阅读全文

怎么按指定区域截图

11-27

void CUserAction::DivBmp(char* caFileName, RECT* prect, int rcount) rn rn//AfxMessageBox("--------------test--------------"); rnFILE* pf = fopen(caFileName, "rb"); rnif (pf == NULL) rnrn AfxMessageBox("test----0");rnreturn; rnrnBITMAPFILEHEADER bm; rnfread(&bm, 1, sizeof(BITMAPFILEHEADER), pf); rnif (bm.bfType!=*(WORD*)"BM") rn rn fclose(pf);rn AfxMessageBox("test----1"); rn return; rn rn BITMAPINFOHEADER bmif; rn fread(&bmif, 1, sizeof(BITMAPINFOHEADER), pf); rn int bmx = bmif.biWidth; rn int bmy = bmif.biHeight>0?bmif.biHeight:(-bmif.biHeight); rn if (bmif.biBitCount < 8 || bmif.biCompression != 0) rn rn fclose(pf); rn AfxMessageBox("test----2");rn return; rn rn RGBQUAD *pRgb = NULL; rn if (bmif.biBitCount == 8) // 256色bmp rn rn pRgb = (RGBQUAD*) new BYTE[bmif.biClrUsed * sizeof(RGBQUAD)]; rn fread(pRgb, bmif.biClrUsed * sizeof(RGBQUAD), 1, pf); rn rn BOOL bAlpha = FALSE; rn if (bmif.biBitCount == 32) rn bAlpha = TRUE;// 带Alpha通道 rn DWORD dwRealWidth = (((bmx * bmif.biBitCount) + 31) >> 5) << 2; rn int iBitSteps = bmif.biBitCount >> 3; rn DWORD iSize = dwRealWidth * bmy; rn BYTE* pBmpData = NULL; rn int readlines = bmy; rn int readszie = iSize; rn int readtimes = bmy / readlines; rn if (iSize > 128 * 1024 * 1024) rn rn readlines = (128 * 1024 * 1024 / dwRealWidth); rn readszie = readlines * dwRealWidth; rn readtimes = bmy / readlines + 1; rn rn DWORD* pDat = new DWORD[bmy * bmx]; rn pBmpData = new BYTE[readszie]; rn fseek(pf, bm.bfOffBits, SEEK_SET); rn fread(pBmpData, 1, readszie, pf); rn int iy,ix; rn BYTE btPil; rn WORD caTmp[3] = 255; rn DWORD dwDataOff = 0; rn int picy = 0; rn for(int n = 0; n < readtimes; ++n) rn rn for (iy = 0; iy < readlines; ++iy) rn rn for (ix = 0; ix < bmx; ix++) rn rn if (pRgb == NULL) rn rn caTmp[0] = pBmpData[(iy * dwRealWidth + ix * iBitSteps) + 2]; rn caTmp[1] = pBmpData[(iy * dwRealWidth + ix * iBitSteps) + 1]; rn caTmp[2] = pBmpData[(iy * dwRealWidth + ix * iBitSteps)]; rn rn else rn rn btPil = pBmpData[(iy * dwRealWidth + ix * iBitSteps)]; rn if (bmif.biClrUsed != 0) rn rn caTmp[0] = pRgb[btPil].rgbRed; rn caTmp[1] = pRgb[btPil].rgbGreen; rn caTmp[2] = pRgb[btPil].rgbBlue; rn rn else rn rn caTmp[0] = caTmp[1] = caTmp[2] = btPil; rn rn rn if (bmif.biHeight < 0) // 有时bmp图像的高会是负值,这时则不用颠倒 rn rn dwDataOff = (iy + picy) * bmx + ix; rn rn else rn rn dwDataOff = (bmy - (iy + picy) - 1) * bmx + ix;rn rn if (bAlpha) rn rn caTmp[3] = pBmpData[(iy * dwRealWidth + ix * iBitSteps) + 3]; rn // ARGB rn pDat[dwDataOff] = caTmp[3] << 24 | caTmp[0] << 16 | caTmp[1] << 8 | caTmp[2] ; rn rn rn picy += readlines; rn int realbits = fread(pBmpData, 1, readszie, pf); rn if (realbits < readszie) readlines = realbits / dwRealWidth; rn rn fclose(pf); rn CString str_test_debug;rn CString str_test_debug_y;rn for (int i = 0; i < rcount; ++i) rn rn //str_test_debug.Format("%d",i);rn //AfxMessageBox(str_test_debug);rn char fbuf[256]; rn sprintf(fbuf, "%d.bmp", i); rn if( (pf = fopen(fbuf, "wb")) != NULL ) rn rn int nWidth = prect[i].right - prect[i].left; rn int nHeight = prect[i].bottom - prect[i].top; rn int nPitch = nWidth; // 保存文件头 rn BITMAPFILEHEADER FileHeader; rn FileHeader.bfType = *(WORD*)"BM"; rn FileHeader.bfSize = nWidth * nHeight * 4 + 0x36; rn FileHeader.bfReserved1 = 0; rn FileHeader.bfReserved2 = 0; rn FileHeader.bfOffBits = 0x36; rn fwrite(&FileHeader, sizeof(BITMAPFILEHEADER), 1, pf); // 保存文件信息 rn BITMAPINFOHEADER Header; rn Header.biSize = sizeof(BITMAPINFOHEADER); // 结构的大小 rn Header.biWidth = nWidth; // 宽 rn Header.biHeight = nHeight; // 高 rn Header.biPlanes = 1; // 固定 rn Header.biBitCount = 32; // 颜色数 rn Header.biCompression = BI_RGB; // 是否压缩 rn Header.biSizeImage = nWidth * nHeight * 4; // 图片的大小 rn Header.biXPelsPerMeter = 0; rn Header.biYPelsPerMeter = 0; rn Header.biClrUsed = 0; rn Header.biClrImportant = 0; rn fwrite(&Header, Header.biSize, 1, pf); // 写入具体内容(从下向上存放) rn fseek(pf, 0x36, SEEK_SET); rn for (int y = prect[i].top; y < prect[i].bottom; ++y) rn rn // fwrite(pDat + (prect[i].bottom - 1 - y) * bmx, 1, (prect[i].right - prect[i].left) * 4, pf); rnfwrite(pDat + (prect[i].bottom - 1 - y) * bmx, (prect[i].right - prect[i].left) * 4,1 , pf); rnstr_test_debug_y.Format("%d",prect[i].bottom - 1 - y);rn//AfxMessageBox(str_test_debug_y);rn rn fclose(pf); rn rn //AfxMessageBox("test123456"); rn rn //AfxMessageBox("test"); rn delete pBmpData; rn delete pDat; rn rnrn----------------------------------rnfor (int y = prect[i].top; y < prect[i].bottom; ++y) rn rn // fwrite(pDat + (prect[i].bottom - 1 - y) * bmx, 1, (prect[i].right - prect[i].left) * 4, pf); rnfwrite(pDat + (prect[i].bottom - 1 - y) * bmx, (prect[i].right - prect[i].left) * 4,1 , pf); rnstr_test_debug_y.Format("%d",prect[i].bottom - 1 - y);rn//AfxMessageBox(str_test_debug_y);rn rn其中这里有点问题,请大师们指导一下。截出来的图不是我想要的。 论坛

区域截图(不用剪贴板)

04-29

下面这段代码可以实现区域截图,但截图后图片保存在剪贴板内,不知道有没有办法不用到剪贴板来实现(剪贴板以外的部份尽量不要改动,准备用这段代码编译成dll).rn[code=VB]Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As LongrnPrivate Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As LongrnPrivate Declare Function EmptyClipboard Lib "user32" () As LongrnPrivate Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As LongrnPrivate Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongrnPrivate Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongrnPrivate Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongrnPrivate Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongrnPrivate Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As LongrnPrivate Declare Function CloseClipboard Lib "user32" () As LongrnPrivate Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As LongrnrnPublic Function SnapArea(xSrc, ySrc, nWidth, nHeight, fp)rnrn SourceDC = CreateDC("DISPLAY", 0, 0, 0) rn DestDC = CreateCompatibleDC(SourceDC) rn Bhandle = CreateCompatibleBitmap(SourceDC, nWidth, nHeight) rn SelectObject DestDC, Bhandle rn BitBlt DestDC, 0, 0, nWidth, nHeight, SourceDC, xSrc, ySrc, &HCC0020rn OpenClipboard 0 rn EmptyClipboard rn SetClipboardData 2, Bhandle rn CloseClipboard rn DeleteDC DestDC rn ReleaseDC Dhandle, SourceDC rn Picture1.Picture = Clipboard.GetData() rn SavePicture Clipboard.GetData(), fp rnEnd FunctionrnrnPrivate Sub Command1_Click()rn Call SnapArea(Text1.Text, Text2.Text, Text3.Text, Text4.Text, "C:\test.bmp") rnEnd Subrn[/code]rnrn[img=http://www.zyyou.com/20090429.jpg][/img] 论坛

后台区域截图的问题

10-09

还是区域截图的问题rn我的想法是rnrn本地载入一张图片 可以是image控件或者是其他的 然后在后台区域截图rnrn但是怎么才能做到后台区域截图 不是直接在webb里面截图了rnrn用区域截图的函数 用下面的函数 虽然句柄写正确以后 但是 在xp的电脑上 还是截图是屏幕的不是后台的程序的控件的截图rnrn而在vin7的电脑上却可以 求改正代码 个人觉得下面的代码好像只能截图屏幕的截图 而不能后台截图rnrn后没有后台区域截图的函数呢rnrnvarrn bmpscreen:Tbitmap;rn jpegscreen:Tjpegimage;rn FullscreenCanvas:TCanvas;rn dc:HDC;rn sourceRect, destRect: TRect;rnbeginrn tryrn //dc:=///GetWindow(GetWindow(form1.WebBrowser1.Handle, GW_CHILD), GW_CHILD);rn dc:=GetWindowDC(form1.Handle);rn //dc:=getdc(getdc(GetWindow(GetWindow(form1.WebBrowser1.Handle, GW_CHILD), GW_CHILD)));rn // dc:=getdc(form1.webbrowser1.Handle);rn ///showmessage(inttostr(dc)) ;rn fullscreencanvas:=Tcanvas.Create;rn fullscreencanvas.Handle:=dc;rn bmpscreen:=Tbitmap.create;rn bmpscreen.Width :=c-a;rn bmpscreen.Height :=d-b;rn sourcerect:=rect(0,0,c-a ,d-b );rn destrect:= rect(a,b,c,d);rn bmpscreen.Canvas.CopyRect(sourcerect,fullscreenCanvas,destrect);rn jpegscreen:=Tjpegimage.Create ;rn jpegscreen.Assign (bmpscreen);rn jpegscreen.CompressionQuality:=100;rn //jpegscreen.SaveToFile(pchar('c:\'+swj));rn jpegscreen.SaveToFile(pchar(ExtractFilePath(ParamStr(0))+swj));rn FullscreenCanvas.Free;rn bmpscreen.Free;rn jpegscreen.Free ;rn ReleaseDC(0, DC);rn exceptrn end;rnend;rn 论坛

没有更多推荐了,返回首页