zoukankan      html  css  js  c++  java
  • VC6.0图形处理5几何变换

    源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522

    //注意如何申请新的存储空间,存放处理后的图片,并利用memcpy,将数据copy给原来存储图像的结构


    void CBMPViewerDoc::OnMenuitem32788() //缩小变换

    {
    // TODO: Add your command handler code here
    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
    int i0 , j0;
    double ratio = 0.5;

    //申请存储空间,并返回指针给lpTemp

    HLOCAL hTemp;

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

    lpTemp = (char*)LocalLock(hTemp);



    unsigned char *lpScr;
    unsigned char * lpDest;
    // 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;
      i0 = (LONG)(i /ratio +0.5);
      j0 = (LONG)(j /ratio + 0.5);
      if((i0 >= 0) && (i0 < bi.biHeight)&&(j0 >= 0 ) && (j0 < bi.biWidth)){
      lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i0 -1) + j0;
    *lpDest = *lpScr;
      }
      
      else {
    *lpDest = 255;  
    }
    }

    }
    memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
    // Invalidata(TRUE);
    UpdateAllViews(NULL,0,NULL);

    }


    void CBMPViewerDoc::OnMenuitem32789() //放大变换
    //只能实现图像区域不变的放大,还不能改变图像的大小
    {
    // TODO: Add your command handler code here


    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
    int i0 , j0;
    double ratio = 2; //放大倍数
    HLOCAL hTemp;
    hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

    LPSTR lpTemp;
    lpTemp = (char*)LocalLock(hTemp);
    unsigned char *lpScr;
    unsigned char * lpDest;
    // 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;
    i0 = (LONG)(i /ratio +0.5);
    j0 = (LONG)(j /ratio + 0.5);
    if((i0 >= 0) && (i0 < bi.biHeight)&&(j0 >= 0 ) && (j0 < bi.biWidth)){
    lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i0 -1) + j0;
    *lpDest = *lpScr;
    }

    else {
    *lpDest = 255;  
    }
    }

    }
    memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
    // Invalidata(TRUE);
    UpdateAllViews(NULL,0,NULL);

    }


    void CBMPViewerDoc::OnMenuitem32784() //旋转变换
    {
    // TODO: Add your command handler code here
    int linewidth;
    linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
    int i0 , j0;
    double RotateAngle = 15; //旋转角度

        double piRotateAngle = RotateAngle * PI/180;


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

    LPSTR lpTemp;
    lpTemp = (char*)LocalLock(hTemp);
    unsigned char *lpScr;
    unsigned char * lpDest;
    // 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;

    i0 = (LONG)(cos(piRotateAngle) * i- sin(piRotateAngle) *j + 0.5);
    j0 = (LONG)(sin(piRotateAngle) *i + cos(piRotateAngle) * j +0.5);

    if((i0 >= 0) && (i0 < bi.biHeight)&&(j0 >= 0 ) && (j0 < bi.biWidth)){
    lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i0 -1) + j0;
    *lpDest = *lpScr;
    }

    else {
    *lpDest = 255;  
    }
    }

    }
    memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
    // Invalidata(TRUE);
    UpdateAllViews(NULL,0,NULL);
    }

  • 相关阅读:
    cobbler自动安装系统(Centos7.X)
    企业级全网服务监控
    javascript中的getElementById、getElementsByName、getElementByTagName详解
    JavaScript中Math对象
    网络编程这结构体发送
    vue中'. native'修饰符的使用
    vue中render: h => h(App)的详细解释
    关于内存对齐的几点记忆
    _initialize() 与__construct()的区别
    PHP的 __DIR__ 作用
  • 原文地址:https://www.cnblogs.com/libing64/p/2878772.html
Copyright © 2011-2022 走看看