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

本文介绍了一种将剪切板中的图像数据保存为BMP格式的方法,通过检测剪切板内容并转换为位图数据,最终实现图像的保存。

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

 

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

 

P.S:优快云的兄弟,能不能不浮夸,不要跟发改委的屁股一样,做技术的贵在塌实,不塌实怎么搞技术。昨天看见一个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;
}
 
折腾一个下午才搞定,结果发现保存的地方不对,对一个备份文件折腾半天,我说怎么老没有变化。而且函数,突然就对了,早晨可能起猛了,一天都晕晕的。。。
 

 

### Altium Designer 中的 PCB 分割与割 在 Altium Designer (AD) 中实现PCB分可以通过创建 V-Cut 或者 Route Cut 来完成。V-Cut 是指制造商按照客户的要求,在指定的位置使用特制工具割形成的一系列用于后续分工序的V形槽[^1]。 对于希望利用软件功能辅助定义这些割路径的设计人员来说,可以在Altium Designer里通过以下方式操作: - **绘制割线**:进入机械层(Mechanical Layer),选择多段线或多边形工具(Polygon Tool),沿着想要分割的地方画出线条作为指示标记。 - **添加制造指令**:为了确保工厂能够识别并执行正确的加工命令,应当向Gerber文件中加入相应的说明文字或者符号。这通常涉及到放置特定属性(Attribute)到图形对象上,比如 `tStop` 和 `bStop` 对于表面贴装技术(SMT)元件下的阻焊层开口;或者是专门针对V-Cut使用的自定义字符串,像 `"VCUT"` 加上下划线以及坐标值表示起始点和结束点的信息。 另外值得注意的是,当考虑实际生产过程中的效率及成本因素时,合理规划整个面化(panelization)方案非常重要。这意味着要考虑到诸如最小间距、支撑柱位置等因素,从而保证最终产品既易于拆解又不会损坏任何组件[^2]。 ```python # Python伪代码展示如何自动化生成V-Cut信息(仅作示意) def add_vcut_info(start_point, end_point): vcut_string = f"VCUT_{start_point}_{end_point}" place_custom_text(vcut_string, mechanical_layer) add_vcut_info((10, 20), (80, 90)) ``` 除了上述方法之外,还可以采用Route Cut的方式来进行更精确的手动控制。这种方式允许设计师直接在布线层(Routing Layers)上描绘具体的走刀轨迹,并且可以调整宽度和其他参数以适应不同需求。 #### 关于去耦电容的注意事项 无论采取哪种形式的物理断手段,在设计阶段都应充分重视电路性能的影响。特别是在处理高频信号或敏感模拟部分时,正确布置去耦电容器至关重要。一般建议靠近IC供电脚位处配置低ESR特性的小容量瓷片电容(如0.01µF)[^3],而对于较大电流波动的应用场合,则额外增加较高耐压等级的大容量钽电解或其他类型的储能器件(例如10µF)来维持稳定电压水平。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值