• VC6.0图形处理10腐蚀膨胀


    void CBMPViewerDoc::OnMenuitem32799() //图像的腐蚀
    {


    //自定义3*3的矩阵作为检验的结构
    // TODO: Add your command handler code here


    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


    unsigned char *lpDest;
    unsigned char *lpScr;



    HLOCAL hTemp;
    hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

    LPSTR lpTemp;
    lpTemp = (char*)LocalLock(hTemp);//以上四句分配一块与源图像数据大小一致的内存块,并返回指针lpTemp
    //暂时存储新建的图片数据,完成后,将数据copy给原数据区

    int pixel;
    // TODO: Add your command handler code here
    for(int i = 0 ; i< bi.biHeight ; i++)
    {
    for(int j = 0 ; j< bi.biWidth ; j++)
    {
        lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
    if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
    *lpDest = *lpScr;




    else
    {

    //lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
    *lpDest = 0;

    for(int s = -1 ; s<=1; s++)
    {
    for(int t = -1; t <= 1;t++)
    {
    lpScr = (unsigned char *)lpBuf + linewidth*(bi.biHeight - i-1 + s) + j + t;
                  
    pixel = *lpScr;
    if(pixel == 255)
    {


    *lpDest = 255;
    }


    }


    }
       

    }

    }

    }

    memcpy(lpBuf , lpTemp, linewidth*bi.biHeight);//新图像数据copy给源数据
    // Invalidata(TRUE);
    UpdateAllViews(NULL,0,NULL);

    }


    void CBMPViewerDoc::OnMenuitem32800() //图像的膨胀
    {

    //自定义结构
    // TODO: Add your command handler code here

    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;

    unsigned char *lpDest;
    unsigned char *lpScr;


    HLOCAL hTemp;
    hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

    LPSTR lpTemp;
    lpTemp = (char*)LocalLock(hTemp);//以上四句分配一块与源图像数据大小一致的内存块,并返回指针lpTemp
    //暂时存储新建的图片数据,完成后,将数据copy给原数据区

    int pixel;
    // TODO: Add your command handler code here
    for(int i = 0 ; i< bi.biHeight ; i++)
    {
    for(int j = 0 ; j< bi.biWidth ; j++)
    {
    lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
    if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
    lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
    *lpDest = *lpScr;



    else
    {

    //lpDest = (unsigned  char *)lpTemp+linewidth*(bi.biHeight - i -1 ) + j ;
    *lpDest = 255;




    for(int s = 0 ; s<=1; s++)
    {
    for(int t = 0; t <= 1;t++)
    {
    lpScr = (unsigned char *)lpBuf + linewidth*(bi.biHeight - i-1 + s) + j + t;

    pixel = *lpScr;
    if(pixel == 0)
    {
    *lpDest = 0;
    }

    }

    }


    }

    }

    }

    memcpy(lpBuf , lpTemp, linewidth*bi.biHeight);//新图像数据copy给源数据
    // Invalidata(TRUE);
    UpdateAllViews(NULL,0,NULL);

    }
  • 相关阅读:
    Windows 服务程序(一)
    API---注册表编程
    API---文件操作
    main(argc, char *argv[])
    C 自删除技术---批处理方式
    分治法排序
    TDD尝试:nodejs单元测试
    尝试create tech team
    Yum重装走过的坑
    求生欲很强的数据库
  • 原文地址:https://www.cnblogs.com/libing64/p/2878766.html
Copyright © 2020-2023  润新知