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);
    }

  • 相关阅读:
    MySQL之数据表的插入内容 空与非空(六)
    输出杨辉三角形
    输入三个double型的数据,放入到a,b,c三个变量中去,使用条件结构与交换逻辑将这三个变量中的值从小到大排列。
    软件测试
    过程设计工具
    设计原理
    总体设计
    生活,也让别人生活
    计算器案例
    需求分析
  • 原文地址:https://www.cnblogs.com/libing64/p/2878772.html
Copyright © 2011-2022 走看看