保存减切板内容为BMP图片 amp;amp; Clipboard save as bmp......

2023-11-10 17:58

本文主要是介绍保存减切板内容为BMP图片 amp;amp; Clipboard save as bmp......,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

保存减切板内容为BMP图片.......

 

最近折腾保存减切板内容为BMP图片。从网上找了N多代码,其中从CSDN里边也找了几个,妈妈的昨天整的我郁闷的是,本来一个差不多1.5M的东西,结果保存成了665M大小的,而且没有大小,没有内容,哪个都不对。日。都是摆渡搞的最后没有办法去外国人那里。还是那里实在啊。找了一个WIN32 CONSOLE的。居然能用。

 

P.S:CSDN的兄弟,能不能不浮夸,不要跟发改委的屁股一样,做技术的贵在塌实,不塌实怎么搞技术。昨天看见一个BMP灰度化的程序,下了,一看狗屁,代码里边啥也没有啊,就这样骗分啊。还有一个说什么VC++的,下来一看是NET || C#的,浪费青春时间啊。不扯淡。GOEO。three mailes on. three mailes down.

the easy day is tomorrow...

 

不知道有没有时间,有时间想把这个作成一个DLL。保存剪切板图片成BMP. JPG. TNF. GIF等等图片,提供原始代码.DLL和相关开发文档。

 

THANKS MSDN,GOOGLE, vicf0kin(not sure).

 

 

Any if you want connect the orign code man please check down lines..

 

You can try to find me via ICQ 371178019
or write an email to
vicf0kin (at) gmail.com
( My Physical location is Ukraine, +2GMT )

http://f0kin.net/page/save-clipboard-bitmap-to-file/

 

 

 

基础知识:

有关的BMP文件格式。Clipboard的知识

参考MSDN,或者MSP出的那个VC6.0技术内幕。

 

 

 

 

//这个函数是响应一个按钮的,我所谓,唯一想说的就是关于里边关于剪切板的知识。

//首先使用剪切板要打开,然后确定内容是BMP格式,最后获得数据。然后使用玩在关闭。

//本着使用时候在申请,实用完关闭的原则,尽管现在机器速度提高了,但是不用的时候常时间占用资源也是

//可耻的行为。

 

 

 

// June 2 2009 AM:9:30........

// 测试系统WINXP  && VS2005.........

 

void CMyDlg::OnBnClickedButtonSaveimg()

{

              //Get the AVI format to clipboard
             if ( !capEditCopy( m_hCapture ) )
            {
                   MessageBox("falied to get window");
                   return;
             }

 

              if ( !::IsClipboardFormatAvailable(CF_BITMAP) )
             {
                    MessageBox("Nothing in BMP buffer");
                    return;
              }

            

              HBITMAP hBitmap = (HBITMAP)GetClipboardData(CF_BITMAP);
 
              if ( hBitmap )
             {
                      GlobalLock(hBitmap);
                      char outfile[255] = "..//June_01.bmp";
                      SaveHBITMAP(hBitmap, outfile);
                      GlobalUnlock(hBitmap);
              }//_IF
             else
             {
  
                     OpenClipboard();
                    if (IsClipboardFormatAvailable(CF_BITMAP))
                   {
                             if ( hBitmap = (HBITMAP)GetClipboardData(CF_BITMAP) )
                             {
                                     GlobalLock(hBitmap);
                                     char outfile[255] = "..//June_01.bmp";
                                     SaveHBITMAP(hBitmap, outfile);
                                     GlobalUnlock(hBitmap);
                              }//_IF
                   }//_IF
             // Failed to open clipboard return
            

            return;
             }//_ELSE

 

             return;
}

 

 


 

 

int CMyDlg::SaveHBITMAP( HBITMAP hB, char * lpsz_FileName )
{  
 BITMAP csBitmap;
 int nRetValue = GetObject(hB, sizeof(csBitmap), &csBitmap);
 unsigned long n_BPP, n_Width, n_Height;
 if (nRetValue)
 {  
  n_Width = (long)csBitmap.bmWidth;
  n_Height = (long)csBitmap.bmHeight;  
  n_BPP = (long)csBitmap.bmBitsPixel;
  long sz = csBitmap.bmWidth*csBitmap.bmHeight*(csBitmap.bmBitsPixel>>3);
  csBitmap.bmBits = (void *) new BYTE[ sz ];
  GetBitmapBits((HBITMAP)hB, sz, csBitmap.bmBits );
  printf( "Proceeding Image %dx%d, BPP=%d", n_Width, n_Height, n_BPP, csBitmap.bmBits );
 }
 else
 {
  printf( "Invalid Object in Clipboard Buffer" );
  return 1;
 }  

 DWORD *lp_Canvas = new DWORD[ n_Width * n_Height]; 
 if ( n_BPP == 32 )
 { 
  for ( unsigned long y = 0; y < n_Height; y ++ )
  {   
   for ( unsigned long x = 0; x < n_Width; x ++ )
   {
    RGBQUAD * rgb = ((RGBQUAD *) ((char*)(csBitmap.bmBits) + csBitmap.bmWidthBytes*y + x*sizeof(DWORD)) );
    lp_Canvas[ (n_Height - 1 - y)*n_Width + x ] = *((DWORD *)rgb);
   }
  }
 }
 else if ( n_BPP == 24 )
 {  
  for ( unsigned long y = 0; y < n_Height; y ++ )
  {   
   for ( unsigned long x = 0; x < n_Width; x ++ )
   {
    RGBTRIPLE rgbi = *((RGBTRIPLE *) ((char*)(csBitmap.bmBits) + csBitmap.bmWidthBytes*y + x*3) );
    RGBQUAD rgbq;    
    rgbq.rgbRed = rgbi.rgbtRed;
    rgbq.rgbGreen = rgbi.rgbtGreen; 
    rgbq.rgbBlue = rgbi.rgbtBlue;    
    lp_Canvas[ (n_Height - 1 - y)*n_Width + x ] = *((DWORD *)(&rgbq));
   }
  }
 }
 else
 {  // here I could handle other resultions also, but I think it is   
  // too obvoius to add them here....  
 }  
 unsigned long n_Bits = 32;
 FILE *pFile = fopen(lpsz_FileName, "wb");       
 if( pFile == NULL )
 {
  printf("File Cannot Be Written");
  return 1;
 }
 // save bitmap file header 
 BITMAPFILEHEADER fileHeader; 
 fileHeader.bfType = 0x4d42; 
 fileHeader.bfSize = 0; 
 fileHeader.bfReserved1 = 0; 
 fileHeader.bfReserved2 = 0; 
 fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 
 fwrite( (char*)&fileHeader, sizeof(fileHeader), 1, pFile );
 // save bitmap info header 
 BITMAPINFOHEADER infoHeader; 
 infoHeader.biSize = sizeof(infoHeader); 
 infoHeader.biWidth = n_Width; 
 infoHeader.biHeight = n_Height; 
 infoHeader.biPlanes = 1; 
 infoHeader.biBitCount = n_Bits; 
 infoHeader.biCompression = BI_RGB; 
 infoHeader.biSizeImage = 0; 
 infoHeader.biXPelsPerMeter = 0;
 infoHeader.biYPelsPerMeter = 0; infoHeader.biClrUsed = 0;
 infoHeader.biClrImportant = 0; 
 fwrite( (char*)&infoHeader, sizeof(infoHeader), 1, pFile );
 fwrite( (char*)lp_Canvas, 1, (n_Bits >> 3)*n_Width*n_Height, pFile );
 fclose( pFile );
 return 0;

}

 

 

 

原始程序是控制台的,从网上拷下来的时候,整理花了很长时间。VS2005下一个HOT KEY是ALT && F8....

 

/*
int SaveHBITMAP( HBITMAP hB, char * lpsz_FileName )
{  
 BITMAP csBitmap;
 int nRetValue = GetObject(hB, sizeof(csBitmap), &csBitmap);
 unsigned long n_BPP, n_Width, n_Height;
 if (nRetValue)
 {  
  n_Width = (long)csBitmap.bmWidth;
  n_Height = (long)csBitmap.bmHeight;  
  n_BPP = (long)csBitmap.bmBitsPixel;
  long sz = csBitmap.bmWidth*csBitmap.bmHeight*(csBitmap.bmBitsPixel>>3);
  csBitmap.bmBits = (void *) new BYTE[ sz ];
  GetBitmapBits((HBITMAP)hB, sz, csBitmap.bmBits );
  printf( "Proceeding Image %dx%d, BPP=%d", n_Width, n_Height, n_BPP, csBitmap.bmBits );
 }
 else
 {
  printf( "Invalid Object in Clipboard Buffer" );
  return 1;
 }  

 DWORD *lp_Canvas = new DWORD[ n_Width * n_Height]; 
 if ( n_BPP == 32 )
 { 
  for ( unsigned long y = 0; y < n_Height; y ++ )
  {   
   for ( unsigned long x = 0; x < n_Width; x ++ )
   {
    RGBQUAD * rgb = ((RGBQUAD *) ((char*)(csBitmap.bmBits) + csBitmap.bmWidthBytes*y + x*sizeof(DWORD)) );
    lp_Canvas[ (n_Height - 1 - y)*n_Width + x ] = *((DWORD *)rgb);
   }
  }
 }
 else if ( n_BPP == 24 )
 {  
  for ( unsigned long y = 0; y < n_Height; y ++ )
  {   
   for ( unsigned long x = 0; x < n_Width; x ++ )
   {
    RGBTRIPLE rgbi = *((RGBTRIPLE *) ((char*)(csBitmap.bmBits) + csBitmap.bmWidthBytes*y + x*3) );
    RGBQUAD rgbq;    
    rgbq.rgbRed = rgbi.rgbtRed;
    rgbq.rgbGreen = rgbi.rgbtGreen; 
    rgbq.rgbBlue = rgbi.rgbtBlue;    
    lp_Canvas[ (n_Height - 1 - y)*n_Width + x ] = *((DWORD *)(&rgbq));
   }
  }
 }
 else
 {  // here I could handle other resultions also, but I think it is   
  // too obvoius to add them here....  
 }  
 unsigned long n_Bits = 32;
 FILE *pFile = fopen(lpsz_FileName, "wb");       
 if(pFile == NULL)
 {
  printf("File Cannot Be Written");
  return 1;
 }
 // save bitmap file header 
 BITMAPFILEHEADER fileHeader; 
 fileHeader.bfType = 0x4d42; 
 fileHeader.bfSize = 0; 
 fileHeader.bfReserved1 = 0; 
 fileHeader.bfReserved2 = 0; 
 fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 
 fwrite( (char*)&fileHeader, sizeof(fileHeader), 1, pFile );
 // save bitmap info header 
 BITMAPINFOHEADER infoHeader; 
 infoHeader.biSize = sizeof(infoHeader); 
 infoHeader.biWidth = n_Width; 
 infoHeader.biHeight = n_Height; 
 infoHeader.biPlanes = 1; 
 infoHeader.biBitCount = n_Bits; 
 infoHeader.biCompression = BI_RGB; 
 infoHeader.biSizeImage = 0; 
 infoHeader.biXPelsPerMeter = 0;
 infoHeader.biYPelsPerMeter = 0; infoHeader.biClrUsed = 0;
 infoHeader.biClrImportant = 0; 
 fwrite( (char*)&infoHeader, sizeof(infoHeader), 1, pFile );
 fwrite( (char*)lp_Canvas, 1, (n_Bits >> 3)*n_Width*n_Height, pFile );
 fclose( pFile );
 return 0;

}
 
int main( int, char ** )

 if (!::IsClipboardFormatAvailable(CF_BITMAP))
 {  
  printf( "Nothing in BMP buffer" );
  return 0;
 } 
 if ( OpenClipboard ( 0 ) )
 {  
  HBITMAP hBitmap = (HBITMAP)GetClipboardData( CF_BITMAP );
  CloseClipboard();  
  if ( hBitmap )
  { 
   GlobalLock( hBitmap );  
   char outfile[255] = "clipboard.bmp";
   SaveHBITMAP( hBitmap, outfile );   
   GlobalUnlock( hBitmap );
  }
  else
  {
   printf( "Nothing in buffer" ); 
  }
 }
 else
 {
  printf( "Windows Clipboard cannot be opened" ); 
 }

 return 0;
}

//http://f0kin.net/page/save-clipboard-bitmap-to-file/

*/

 

 

 

现在还没有具体分析哪个保存代码。有关BMP,Cilpboard,File, 请参考MSDN。只能说一句话。相信MSDN比相信党的精神还有用,很和谐,很强大。

 

 

希望有时间能完成DLL化的工作。。

 

 

 

//-----------------------------------------------------------------

June_02_2009 AM: 9:33

 

Code by sealplusplus...

 

 

World is shit.....

 

                  ----------General Patton

 

 

 

 

 

// Update.......

DataSave( char* lpSaveData, int nDataSize )
{
        int nDataLen;
        if  ( !lpSaveData )
       {
              m_strStatus = " Save Data Invalid";
              m_EditState.SetWindowTextW( m_strStatus );
              return 0;
        }//_IF
 
        FILE *fDataSave;
        // Open for wriite
        if ( fopen_s( &fDataSave, "..//SaveDataLog.txt", "a+t") == NULL )
        {
              nDataLen = fwrite( "/n", sizeof(char), 1, fDataSave );
              nDataLen = fwrite( lpSaveData,sizeof(char), nDataSize,  fDataSave );
                if ( nDataLen == nDataSize )
               {
                       fclose( fDataSave );
                       return nDataLen;
                }//_IF
        }//_IF
        else
        {
                // Code error
         }//_ELSE
 
         fclose( fDataSave );
          return 0;
}
 
折腾一个下午才搞定,结果发现保存的地方不对,对一个备份文件折腾半天,我说怎么老没有变化。而且函数,突然就对了,早晨可能起猛了,一天都晕晕的。。。
 

 

这篇关于保存减切板内容为BMP图片 amp;amp; Clipboard save as bmp......的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/384339

相关文章

如何解决Pycharm编辑内容时有光标的问题

《如何解决Pycharm编辑内容时有光标的问题》文章介绍了如何在PyCharm中配置VimEmulator插件,包括检查插件是否已安装、下载插件以及安装IdeaVim插件的步骤... 目录Pycharm编辑内容时有光标1.如果Vim Emulator前面有对勾2.www.chinasem.cn如果tools工

Python利用PIL进行图片压缩

《Python利用PIL进行图片压缩》有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所以本文为大家介绍了Python中图片压缩的方法,需要的可以参考下... 有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所有可以对文件中的图

java获取图片的大小、宽度、高度方式

《java获取图片的大小、宽度、高度方式》文章介绍了如何将File对象转换为MultipartFile对象的过程,并分享了个人经验,希望能为读者提供参考... 目China编程录Java获取图片的大小、宽度、高度File对象(该对象里面是图片)MultipartFile对象(该对象里面是图片)总结java获取图片

使用C++将处理后的信号保存为PNG和TIFF格式

《使用C++将处理后的信号保存为PNG和TIFF格式》在信号处理领域,我们常常需要将处理结果以图像的形式保存下来,方便后续分析和展示,C++提供了多种库来处理图像数据,本文将介绍如何使用stb_ima... 目录1. PNG格式保存使用stb_imagephp_write库1.1 安装和包含库1.2 代码解

Java实战之自助进行多张图片合成拼接

《Java实战之自助进行多张图片合成拼接》在当今数字化时代,图像处理技术在各个领域都发挥着至关重要的作用,本文为大家详细介绍了如何使用Java实现多张图片合成拼接,需要的可以了解下... 目录前言一、图片合成需求描述二、图片合成设计与实现1、编程语言2、基础数据准备3、图片合成流程4、图片合成实现三、总结前

C#比较两个List集合内容是否相同的几种方法

《C#比较两个List集合内容是否相同的几种方法》本文详细介绍了在C#中比较两个List集合内容是否相同的方法,包括非自定义类和自定义类的元素比较,对于非自定义类,可以使用SequenceEqual、... 目录 一、非自定义类的元素比较1. 使用 SequenceEqual 方法(顺序和内容都相等)2.

使用Python实现图片和base64转换工具

《使用Python实现图片和base64转换工具》这篇文章主要为大家详细介绍了如何使用Python中的base64模块编写一个工具,可以实现图片和Base64编码之间的转换,感兴趣的小伙伴可以了解下... 简介使用python的base64模块来实现图片和Base64编码之间的转换。可以将图片转换为Bas

css实现图片旋转功能

《css实现图片旋转功能》:本文主要介绍了四种CSS变换效果:图片旋转90度、水平翻转、垂直翻转,并附带了相应的代码示例,详细内容请阅读本文,希望能对你有所帮助... 一 css实现图片旋转90度.icon{ -moz-transform:rotate(-90deg); -webkit-transfo

vscode保存代码时自动eslint格式化图文教程

《vscode保存代码时自动eslint格式化图文教程》:本文主要介绍vscode保存代码时自动eslint格式化的相关资料,包括打开设置文件并复制特定内容,文中通过代码介绍的非常详细,需要的朋友... 目录1、点击设置2、选择远程--->点击右上角打开设置3、会弹出settings.json文件,将以下内

C#实现添加/替换/提取或删除Excel中的图片

《C#实现添加/替换/提取或删除Excel中的图片》在Excel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更加美观,下面我们来看看如何在C#中实现添加/替换/提取或删除E... 在Excandroidel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更