×
Namespaces

Variants
Actions

如何使用CImageEncoder进行图片压缩转换

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95 8GB, Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd/5th Edition
S60 5th Edition
Article
Keywords: image encoding
Created: User:Kevin8093 (14 May 2009)
Last edited: hamishwillee (26 Jul 2011)

以下代码示例说明如何在Symbian C++使用CImageEncoder进行bmp图片压缩和转换成Jpg图片。

1. 取得屏幕旋转方向和大小信息并截取当前屏幕

//取得屏幕设备指针
const CWsScreenDevice* screenDevice = iCoeEnv.ScreenDevice();
    
//取得屏幕大小和方向信息
screenDevice->GetScreenModeSizeAndRotation(
screenDevice->CurrentScreenMode(), iSizeAndRotation);

//截屏操作
CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap();
iBitmap->Create(iSizeAndRotation.iPixelSize, screenDevice->DisplayMode());

iBitmap->SetSizeInTwips(screenDevice);

screenDevice->CopyScreenToBitmap(iBitmap);

2. 设置需要转化文件的格式和参数,使用异步方法进行压缩。

//生成一个CFrameImageData对象的指针
CFrameImageData* frameImageData = CFrameImageData::NewL();
CleanupStack::PushL(frameImageData);
 
//转化成Jpeg格式的参数设定,iSampleScheme,iQualityFactor
TJpegImageData* imageData = new (ELeave) TJpegImageData();
imageData->iSampleScheme  = TJpegImageData::EColor444;
imageData->iQualityFactor = iSettingData.ImageQuality();
User::LeaveIfError(frameImageData->AppendImageData(imageData));

//DataNewL方法来制定转换的格式和方法
iImageEncoder = CImageEncoder::DataNewL
(iCapturedImageBuffer, KImageTypeJpg, CImageEncoder::EOptionAlwaysThread);
    
//异步请求转化为指定格式的文件
iImageEncoder->Convert(&iStatus, *iBitmap, frameImageData);

CleanupStack::PopAndDestroy(frameImageData);

上述代码片段由于使用了异步方法,需要在活动对象中(Active Object)使用。

同理,使用CImageEncoder也可进行其他图片格式的转换。

This page was last modified on 26 July 2011, at 05:47.
29 page views in the last 30 days.