如何使用CImageEncoder進行圖片壓縮轉換

來源:互聯網
上載者:User

以下程式碼範例說明如何在Symbian C++使用CImageEncoder進行bmp圖片壓縮和轉換成Jpg圖片。

Tested on: Nokia N958GB, Nokia 5800Xpress Music

1. 取得旋轉螢幕方向和大小資訊並截取當前螢幕

 1 //取得螢幕裝置指標
 2 const CWsScreenDevice* screenDevice = iCoeEnv.ScreenDevice();
 3     
 4 //取得螢幕大小和方向資訊
 5 screenDevice->GetScreenModeSizeAndRotation(
 6   screenDevice->CurrentScreenMode(), iSizeAndRotation);
 7 
 8 //截屏操作
 9 CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap();
10     iBitmap->Create(iSizeAndRotation.iPixelSize, screenDevice->DisplayMode());
11 
12 iBitmap->SetSizeInTwips(screenDevice);
13 
14 screenDevice->CopyScreenToBitmap(iBitmap);

 

2. 設定需要轉化檔案的格式和參數,使用非同步方法呼叫進行壓縮。

 1 //產生一個CFrameImageData對象的指標
 2 CFrameImageData* frameImageData = CFrameImageData::NewL();
 3 CleanupStack::PushL(frameImageData);
 4 
 5 //轉化成Jpeg格式的參數設定,iSampleScheme,iQualityFactor
 6 TJpegImageData* imageData = new (ELeave) TJpegImageData();
 7 imageData->iSampleScheme  = TJpegImageData::EColor444;
 8 imageData->iQualityFactor = iSettingData.ImageQuality();
 9 User::LeaveIfError(frameImageData->AppendImageData(imageData));
10 
11 //DataNewL方法來制定轉換的格式和方法
12 iImageEncoder = CImageEncoder::DataNewL
13     (iCapturedImageBuffer, KImageTypeJpg, CImageEncoder::EOptionAlwaysThread);
14     
15 //非同步請求轉化為指定格式的檔案
16 iImageEncoder->Convert(&iStatus, *iBitmap, frameImageData);
17 
18 CleanupStack::PopAndDestroy(frameImageData);
19 

 

上述程式碼片段由於使用了非同步方法呼叫,需要在使用中的物件中(Active Object)使用。

同理,使用CImageEncoder也可進行其他圖片格式的轉換。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.