本帖最后由 qqqwwwwww 于 2009-07-25 09:59:25 编辑

解决方案 »

  1.   

    位图的分辨率可以用HorizontalResolution和VerticalResolution获得 
      

  2.   

    void   REsizeImage(BYTE   *InImage,unsigned   SWidth,unsigned   SHeight,BYTE   *OutImage,unsigned   DWidth,unsigned   DHeight)  
      {  
              unsigned   int   PtAR=0,PtBR=0,PtCR=0,PtDR=0,PixelValueR=0;  
                unsigned   int   PtAG=0,PtBG=0,PtCG=0,PtDG=0,PixelValueG=0;  
                unsigned   int   PtAB=0,PtBB=0,PtCB=0,PtDB=0,PixelValueB=0;  
                register   unsigned   SpixelColNum=0,SpixelRowNum=0,DestCol=0,DestRow=0;  
                unsigned   int     SpixelColAddr=0,SpixelRowAddr=0;  
                unsigned   int   ColDelta=0,RowDelta=0,scaleV=0,scaleH=0;  
                unsigned   int   ContribAandBR=0,ContribCandDR=0;  
                unsigned   int   ContribAandBG=0,ContribCandDG=0;  
                unsigned   int   ContribAandBB=0,ContribCandDB=0;  
                unsigned   int   ContribTem[2048*3];//图片最大宽度不超过2048  
                int   i=0;  
                 
                scaleH=(SWidth<<8)/DWidth;  
                scaleV=(SHeight<<8)/DHeight;  
                  ///////////////////////////  
                    ///first   line  
                    /////////////////////  
                    for(DestCol=0;DestCol<DWidth;DestCol++)  
                    {  
                         
                    SpixelColAddr=DestCol*scaleH;  
                    ColDelta=SpixelColAddr&255;  
                    SpixelColNum=(SpixelColAddr-ColDelta)>>8;  
                    PtAB=InImage[3*SpixelRowNum*SWidth+3*SpixelColNum];  
                    PtAG=InImage[3*SpixelRowNum*SWidth+3*SpixelColNum+1];                  
                    PtAR=InImage[3*SpixelRowNum*SWidth+3*SpixelColNum+2];  
                         
                         
                         
                        if((SpixelColNum+1)<SWidth)  
                        {  
                            PtBB=InImage[3*SpixelRowNum*SWidth+3*(SpixelColNum+1)];  
                            PtBG=InImage[3*SpixelRowNum*SWidth+3*(SpixelColNum+1)+1];  
                            PtBR=InImage[3*SpixelRowNum*SWidth+3*(SpixelColNum+1)+2];  
                             
                            PtCB=InImage[3*(SpixelRowNum+1)*SWidth+3*SpixelColNum];  
                            PtCG=InImage[3*(SpixelRowNum+1)*SWidth+3*SpixelColNum+1];  
                            PtCR=InImage[3*(SpixelRowNum+1)*SWidth+3*SpixelColNum+2];  
                             
                            PtDB=InImage[3*(SpixelRowNum+1)*SWidth+3*(SpixelColNum+1)];  
                            PtDG=InImage[3*(SpixelRowNum+1)*SWidth+3*(SpixelColNum+1)+1];  
                            PtDR=InImage[3*(SpixelRowNum+1)*SWidth+3*(SpixelColNum+1)+2];  
                             
                             
                        }  
                        else  
                        {  
                                PtBB=PtCB=PtDB=PtAB;  
                                PtBG=PtCG=PtDG=PtAG;  
                                PtBR=PtCR=PtDR=PtAR;  
                        }  
                         
                         
                        ContribAandBB=ColDelta*(PtBB-PtAB)+PtAB*256;  
                        ContribCandDB=ColDelta*(PtDB-PtCB)+PtCB*256;  
                        ContribTem[i++]=ContribCandDB;  
                        PixelValueB=(ContribAandBB*256+(ContribCandDB-ContribAandBB)*RowDelta)>>16;  
                         
                        ContribAandBG=ColDelta*(PtBG-PtAG)+PtAG*256;  
                        ContribCandDG=ColDelta*(PtDG-PtCG)+PtCG*256;  
                        ContribTem[i++]=ContribCandDG;  
                        PixelValueG=(ContribAandBG*256+(ContribCandDG-ContribAandBG)*RowDelta)>>16;  
                         
                        ContribAandBR=ColDelta*(PtBR-PtAR)+PtAR*256;  
                        ContribCandDR=ColDelta*(PtDR-PtCR)+PtCR*256;  
                        ContribTem[i++]=ContribCandDR;  
                        PixelValueR=(ContribAandBR*256+(ContribCandDR-ContribAandBR)*RowDelta)>>16;  
                         
                        OutImage[3*DestRow*DWidth+3*DestCol]=PixelValueB;  
                        OutImage[3*DestRow*DWidth+3*DestCol+1]=PixelValueG;  
                        OutImage[3*DestRow*DWidth+3*DestCol+2]=PixelValueR;  
                    }  
                     
                     
              //////////other   line//////////  
               
                for(DestRow=1;DestRow<DHeight;DestRow++)  
                {  
                      i=0;                                                                            
                    SpixelRowAddr=DestRow*scaleV;  
                    RowDelta=SpixelRowAddr&255;  
                    SpixelRowNum=(SpixelRowAddr-RowDelta)>>8;  
                   
                     
                     
                    for(DestCol=0;DestCol<DWidth;DestCol++)  
                    {  
                         
                    SpixelColAddr=DestCol*scaleH;  
                    ColDelta=SpixelColAddr&255;  
                    SpixelColNum=(SpixelColAddr-ColDelta)>>8;  
                    PtAB=InImage[3*SpixelRowNum*SWidth+3*SpixelColNum];  
                    PtAG=InImage[3*SpixelRowNum*SWidth+3*SpixelColNum+1];                  
                    PtAR=InImage[3*SpixelRowNum*SWidth+3*SpixelColNum+2];  
                         
                         
                         
                        if(((SpixelColNum+1)<SWidth)&&((SpixelRowNum+1)<SHeight))  
                        {  
                            //PtBB=InImage[3*SpixelRowNum*SWidth+3*(SpixelColNum+1)];  
                            //PtBG=InImage[3*SpixelRowNum*SWidth+3*(SpixelColNum+1)+1];  
                            //PtBR=InImage[3*SpixelRowNum*SWidth+3*(SpixelColNum+1)+2];  
                             
                            PtCB=InImage[3*(SpixelRowNum+1)*SWidth+3*SpixelColNum];  
                            PtCG=InImage[3*(SpixelRowNum+1)*SWidth+3*SpixelColNum+1];  
                            PtCR=InImage[3*(SpixelRowNum+1)*SWidth+3*SpixelColNum+2];  
                             
                            PtDB=InImage[3*(SpixelRowNum+1)*SWidth+3*(SpixelColNum+1)];  
                            PtDG=InImage[3*(SpixelRowNum+1)*SWidth+3*(SpixelColNum+1)+1];  
                            PtDR=InImage[3*(SpixelRowNum+1)*SWidth+3*(SpixelColNum+1)+2];  
                             
                             
                        }  
                        else  
                        {  
                                PtBB=PtCB=PtDB=PtAB;  
                                PtBG=PtCG=PtDG=PtAG;  
                                PtBR=PtCR=PtDR=PtAR;  
                        }  
                         
                         
                        ContribAandBB=ContribTem[i];  
                        ContribCandDB=ColDelta*(PtDB-PtCB)+PtCB*256;  
                        ContribTem[i++]=ContribCandDB;  
                        PixelValueB=(ContribAandBB*256+(ContribCandDB-ContribAandBB)*RowDelta)>>16;  
                         
                        ContribAandBG=ContribTem[i];  
                        ContribCandDG=ColDelta*(PtDG-PtCG)+PtCG*256;  
                        ContribTem[i++]=ContribCandDG;  
                        PixelValueG=(ContribAandBG*256+(ContribCandDG-ContribAandBG)*RowDelta)>>16;  
                         
                        ContribAandBR=ContribTem[i];  
                        ContribCandDR=ColDelta*(PtDR-PtCR)+PtCR*256;  
                        ContribTem[i++]=ContribCandDR;  
                        PixelValueR=(ContribAandBR*256+(ContribCandDR-ContribAandBR)*RowDelta)>>16;  
                         
                        OutImage[3*DestRow*DWidth+3*DestCol]=PixelValueB;  
                        OutImage[3*DestRow*DWidth+3*DestCol+1]=PixelValueG;  
                        OutImage[3*DestRow*DWidth+3*DestCol+2]=PixelValueR;  
                    }  
                     
                }  
                 
      }