本文整理汇总了C++中SkTScopedComPtr::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ SkTScopedComPtr::Write方法的具体用法?C++ SkTScopedComPtr::Write怎么用?C++ SkTScopedComPtr::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkTScopedComPtr
的用法示例。
在下文中一共展示了SkTScopedComPtr::Write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onEncode
bool SkImageEncoder_WIC::onEncode(SkWStream* stream
, const SkBitmap& bm
, int quality)
{
GUID type;
switch (fType) {
case kJPEG_Type:
type = GUID_ContainerFormatJpeg;
break;
case kPNG_Type:
type = GUID_ContainerFormatPng;
break;
default:
return false;
}
//Initialize COM.
AutoCoInitialize scopedCo;
HRESULT hr = scopedCo.getHR();
//Create Windows Imaging Component ImagingFactory.
SkTScopedComPtr<IWICImagingFactory> piImagingFactory;
if (SUCCEEDED(hr)) {
hr = CoCreateInstance(
CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
, IID_PPV_ARGS(&piImagingFactory)
);
}
//Convert the SkWStream to an IStream.
SkTScopedComPtr<IStream> piStream;
if (SUCCEEDED(hr)) {
hr = SkWIStream::CreateFromSkWStream(stream, &piStream);
}
//Create an encode of the appropriate type.
SkTScopedComPtr<IWICBitmapEncoder> piEncoder;
if (SUCCEEDED(hr)) {
hr = piImagingFactory->CreateEncoder(type, NULL, &piEncoder);
}
if (SUCCEEDED(hr)) {
hr = piEncoder->Initialize(piStream.get(), WICBitmapEncoderNoCache);
}
//Create a the frame.
SkTScopedComPtr<IWICBitmapFrameEncode> piBitmapFrameEncode;
SkTScopedComPtr<IPropertyBag2> piPropertybag;
if (SUCCEEDED(hr)) {
hr = piEncoder->CreateNewFrame(&piBitmapFrameEncode, &piPropertybag);
}
if (SUCCEEDED(hr)) {
PROPBAG2 name = { 0 };
name.dwType = PROPBAG2_TYPE_DATA;
name.vt = VT_R4;
name.pstrName = L"ImageQuality";
VARIANT value;
VariantInit(&value);
value.vt = VT_R4;
value.fltVal = (FLOAT)(quality / 100.0);
//Ignore result code.
// This returns E_FAIL if the named property is not in the bag.
//TODO(bungeman) enumerate the properties,
// write and set hr iff property exists.
piPropertybag->Write(1, &name, &value);
}
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->Initialize(piPropertybag.get());
}
//Set the size of the frame.
const UINT width = bm.width();
const UINT height = bm.height();
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->SetSize(width, height);
}
//Set the pixel format of the frame.
const WICPixelFormatGUID formatDesired = GUID_WICPixelFormat32bppBGRA;
WICPixelFormatGUID formatGUID = formatDesired;
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->SetPixelFormat(&formatGUID);
}
if (SUCCEEDED(hr)) {
//Be sure the image format is the one requested.
hr = IsEqualGUID(formatGUID, formatDesired) ? S_OK : E_FAIL;
}
//Write the pixels into the frame.
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->WritePixels(
height
, bm.rowBytes()
, bm.rowBytes()*height
, reinterpret_cast<BYTE*>(bm.getPixels()));
//.........这里部分代码省略.........
示例2: onEncode
//.........这里部分代码省略.........
if (!scopedCo.succeeded()) {
return false;
}
HRESULT hr = S_OK;
//Create Windows Imaging Component ImagingFactory.
SkTScopedComPtr<IWICImagingFactory> piImagingFactory;
if (SUCCEEDED(hr)) {
hr = CoCreateInstance(
CLSID_WICImagingFactory
, nullptr
, CLSCTX_INPROC_SERVER
, IID_PPV_ARGS(&piImagingFactory)
);
}
//Convert the SkWStream to an IStream.
SkTScopedComPtr<IStream> piStream;
if (SUCCEEDED(hr)) {
hr = SkWIStream::CreateFromSkWStream(stream, &piStream);
}
//Create an encode of the appropriate type.
SkTScopedComPtr<IWICBitmapEncoder> piEncoder;
if (SUCCEEDED(hr)) {
hr = piImagingFactory->CreateEncoder(type, nullptr, &piEncoder);
}
if (SUCCEEDED(hr)) {
hr = piEncoder->Initialize(piStream.get(), WICBitmapEncoderNoCache);
}
//Create a the frame.
SkTScopedComPtr<IWICBitmapFrameEncode> piBitmapFrameEncode;
SkTScopedComPtr<IPropertyBag2> piPropertybag;
if (SUCCEEDED(hr)) {
hr = piEncoder->CreateNewFrame(&piBitmapFrameEncode, &piPropertybag);
}
if (SUCCEEDED(hr)) {
PROPBAG2 name = { 0 };
name.dwType = PROPBAG2_TYPE_DATA;
name.vt = VT_R4;
name.pstrName = L"ImageQuality";
VARIANT value;
VariantInit(&value);
value.vt = VT_R4;
value.fltVal = (FLOAT)(quality / 100.0);
//Ignore result code.
// This returns E_FAIL if the named property is not in the bag.
//TODO(bungeman) enumerate the properties,
// write and set hr iff property exists.
piPropertybag->Write(1, &name, &value);
}
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->Initialize(piPropertybag.get());
}
//Set the size of the frame.
const UINT width = bitmap->width();
const UINT height = bitmap->height();
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->SetSize(width, height);
}
//Set the pixel format of the frame.
const WICPixelFormatGUID formatDesired = GUID_WICPixelFormat32bppBGRA;
WICPixelFormatGUID formatGUID = formatDesired;
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->SetPixelFormat(&formatGUID);
}
if (SUCCEEDED(hr)) {
//Be sure the image format is the one requested.
hr = IsEqualGUID(formatGUID, formatDesired) ? S_OK : E_FAIL;
}
//Write the pixels into the frame.
if (SUCCEEDED(hr)) {
SkAutoLockPixels alp(*bitmap);
const UINT stride = (UINT) bitmap->rowBytes();
hr = piBitmapFrameEncode->WritePixels(
height
, stride
, stride * height
, reinterpret_cast<BYTE*>(bitmap->getPixels()));
}
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->Commit();
}
if (SUCCEEDED(hr)) {
hr = piEncoder->Commit();
}
return SUCCEEDED(hr);
}