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

相关文章

Python实现AVIF图片与其他图片格式间的批量转换

《Python实现AVIF图片与其他图片格式间的批量转换》这篇文章主要为大家详细介绍了如何使用Pillow库实现AVIF与其他格式的相互转换,即将AVIF转换为常见的格式,比如JPG或PNG,需要的小... 目录环境配置1.将单个 AVIF 图片转换为 JPG 和 PNG2.批量转换目录下所有 AVIF 图

详解如何通过Python批量转换图片为PDF

《详解如何通过Python批量转换图片为PDF》:本文主要介绍如何基于Python+Tkinter开发的图片批量转PDF工具,可以支持批量添加图片,拖拽等操作,感兴趣的小伙伴可以参考一下... 目录1. 概述2. 功能亮点2.1 主要功能2.2 界面设计3. 使用指南3.1 运行环境3.2 使用步骤4. 核

Java图片压缩三种高效压缩方案详细解析

《Java图片压缩三种高效压缩方案详细解析》图片压缩通常涉及减少图片的尺寸缩放、调整图片的质量(针对JPEG、PNG等)、使用特定的算法来减少图片的数据量等,:本文主要介绍Java图片压缩三种高效... 目录一、基于OpenCV的智能尺寸压缩技术亮点:适用场景:二、JPEG质量参数压缩关键技术:压缩效果对比

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Python将博客内容html导出为Markdown格式

《Python将博客内容html导出为Markdown格式》Python将博客内容html导出为Markdown格式,通过博客url地址抓取文章,分析并提取出文章标题和内容,将内容构建成html,再转... 目录一、为什么要搞?二、准备如何搞?三、说搞咱就搞!抓取文章提取内容构建html转存markdown

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

使用C#代码在PDF文档中添加、删除和替换图片

《使用C#代码在PDF文档中添加、删除和替换图片》在当今数字化文档处理场景中,动态操作PDF文档中的图像已成为企业级应用开发的核心需求之一,本文将介绍如何在.NET平台使用C#代码在PDF文档中添加、... 目录引言用C#添加图片到PDF文档用C#删除PDF文档中的图片用C#替换PDF文档中的图片引言在当

详解C#如何提取PDF文档中的图片

《详解C#如何提取PDF文档中的图片》提取图片可以将这些图像资源进行单独保存,方便后续在不同的项目中使用,下面我们就来看看如何使用C#通过代码从PDF文档中提取图片吧... 当 PDF 文件中包含有价值的图片,如艺术画作、设计素材、报告图表等,提取图片可以将这些图像资源进行单独保存,方便后续在不同的项目中使

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("

使用Python实现获取网页指定内容

《使用Python实现获取网页指定内容》在当今互联网时代,网页数据抓取是一项非常重要的技能,本文将带你从零开始学习如何使用Python获取网页中的指定内容,希望对大家有所帮助... 目录引言1. 网页抓取的基本概念2. python中的网页抓取库3. 安装必要的库4. 发送HTTP请求并获取网页内容5. 解