保存减切板内容为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

相关文章

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

Python如何去除图片干扰代码示例

《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪

Python中图片与PDF识别文本(OCR)的全面指南

《Python中图片与PDF识别文本(OCR)的全面指南》在数据爆炸时代,80%的企业数据以非结构化形式存在,其中PDF和图像是最主要的载体,本文将深入探索Python中OCR技术如何将这些数字纸张转... 目录一、OCR技术核心原理二、python图像识别四大工具库1. Pytesseract - 经典O

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

Go语言如何判断两张图片的相似度

《Go语言如何判断两张图片的相似度》这篇文章主要为大家详细介绍了Go语言如何中实现判断两张图片的相似度的两种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 在介绍技术细节前,我们先来看看图片对比在哪些场景下可以用得到:图片去重:自动删除重复图片,为存储空间"瘦身"。想象你是一个

使用Python实现base64字符串与图片互转的详细步骤

《使用Python实现base64字符串与图片互转的详细步骤》要将一个Base64编码的字符串转换为图片文件并保存下来,可以使用Python的base64模块来实现,这一过程包括解码Base64字符串... 目录1. 图片编码为 Base64 字符串2. Base64 字符串解码为图片文件3. 示例使用注意

Python实现自动化Word文档样式复制与内容生成

《Python实现自动化Word文档样式复制与内容生成》在办公自动化领域,高效处理Word文档的样式和内容复制是一个常见需求,本文将展示如何利用Python的python-docx库实现... 目录一、为什么需要自动化 Word 文档处理二、核心功能实现:样式与表格的深度复制1. 表格复制(含样式与内容)2