windows mobile 上面固定比例映像縮放

來源:互聯網
上載者:User

最近一段時間太忙,上篇部落格說是把映像縮放的演算法放上來,今天放上來。這個演算法參考的是線性插值法來實現,也就是最簡單的方法,在手機上面受cpu計算能力的限制還有對圖片品質要求不高,所以採用這種演算法。如果需要高品質的話請搜尋濾波像素重採樣。這個代碼輸入和輸入的都是像素矩陣,大家在映像操作的時候應該都是會轉換成的。如果需要全套代碼可以mail我(jessz@live.com)或者留言在這裡,我會把整個dib.cpp檔案發給你,他包括映像解碼,縮放,圖片儲存之類的操作。

//////////////////////////////////////////////////////////////////////////// 功能: 根據固定比例縮放演算法// add by jessezhao/////////////////////////////////////////////////////////////////////////void CDib::PicZoomFixSize( const TPicRegion& Dst,const TPicRegion& Src ){   if ((0==Dst.width)||(0==Dst.height)||(0==Src.width)||(0==Src.height)) return;   // 根據高寬比確認一個最好的縮放比例double dWidth = IMAGE_OPTION_WIDTH;double dHeight = IMAGE_OPTION_HIGHT;double dAspectRatio = (double)((double)dWidth/(double)dHeight);double dPictureWidth = Src.width;double dPictureHeight = Src.height;double dPictureAspectRatio = (double)((double)dPictureWidth/(double)dPictureHeight);   int nCenteringFactor=0;int nNewHeight = 0;int nNewWidth = 0;if (dPictureAspectRatio > dAspectRatio){nNewHeight = (int)(dWidth/dPictureWidth*dPictureHeight);nCenteringFactor = (IMAGE_OPTION_HIGHT - nNewHeight) / 2;}else if (dPictureAspectRatio < dAspectRatio){nNewWidth = (int)(dHeight/dPictureHeight*dPictureWidth);nCenteringFactor = (IMAGE_OPTION_WIDTH - nNewWidth) / 2;}   // 高度合適    if (nNewWidth != 0)    {unsigned long xrIntFloat_16=(Src.width<<16)/nNewWidth+1; unsigned long yrIntFloat_16=(Src.height<<16)/Dst.height+1;unsigned long dst_width=nNewWidth;TARGB32* pDstLine=Dst.pdata;unsigned long srcy_16=0;for (unsigned long y=0;y<Dst.height;++y){TARGB32* pSrcLine=((TARGB32*)((TUInt8*)Src.pdata+Src.byte_width*(srcy_16>>16)));unsigned long srcx_16=0;for (unsigned long x=0;x<nNewWidth;++x){//nCenteringFactor調整在靶心圖表中開始寫入的位置pDstLine[x+nCenteringFactor]=pSrcLine[srcx_16>>16];srcx_16+=xrIntFloat_16;}srcy_16+=yrIntFloat_16;((TUInt8*&)pDstLine)+=Dst.byte_width;}}//寬度合適else if (nNewHeight!=0){unsigned long xrIntFloat_16=(Src.width<<16)/Dst.width+1; unsigned long yrIntFloat_16=(Src.height<<16)/nNewHeight+1;unsigned long dst_width=Dst.width;TARGB32* pDstLine=Dst.pdata;unsigned long srcy_16=0;   //nCenteringFactor調整在靶心圖表中開始寫入的位置((TUInt8*&)pDstLine)+=Dst.byte_width*nCenteringFactor;   for (unsigned long y=0;y<nNewHeight;++y){TARGB32* pSrcLine=((TARGB32*)((TUInt8*)Src.pdata+Src.byte_width*(srcy_16>>16)));unsigned long srcx_16=0;for (unsigned long x=0;x<dst_width;++x){pDstLine[x]=pSrcLine[srcx_16>>16];srcx_16+=xrIntFloat_16;}srcy_16+=yrIntFloat_16;((TUInt8*&)pDstLine)+=Dst.byte_width;}}//長寬等比例縮放符合螢幕比例else{unsigned long xrIntFloat_16=(Src.width<<16)/Dst.width+1; unsigned long yrIntFloat_16=(Src.height<<16)/Dst.height+1;unsigned long dst_width=Dst.width;TARGB32* pDstLine=Dst.pdata;unsigned long srcy_16=0;   for (unsigned long y=0;y<Dst.height;++y){TARGB32* pSrcLine=((TARGB32*)((TUInt8*)Src.pdata+Src.byte_width*(srcy_16>>16)));unsigned long srcx_16=0;for (unsigned long x=0;x<dst_width;++x){pDstLine[x]=pSrcLine[srcx_16>>16];srcx_16+=xrIntFloat_16;}srcy_16+=yrIntFloat_16;((TUInt8*&)pDstLine)+=Dst.byte_width;}}}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.