本文整理汇总了C++中IWICImagingFactory::CreateBitmap方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICImagingFactory::CreateBitmap方法的具体用法?C++ IWICImagingFactory::CreateBitmap怎么用?C++ IWICImagingFactory::CreateBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWICImagingFactory
的用法示例。
在下文中一共展示了IWICImagingFactory::CreateBitmap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveToImageFile
HRESULT SaveToImageFile(PlotData **data
, unsigned int imageWidth, unsigned int imageHeight
, float rangeX, float rangeY
, float leftMargin, float bottomMargin
, float xTick, float yTick)
{
HRESULT hr = S_OK;
//
// Create Factories
//
IWICImagingFactory *pWICFactory = NULL;
ID2D1Factory *pD2DFactory = NULL;
IDWriteFactory *pDWriteFactory = NULL;
IWICBitmap *pWICBitmap = NULL;
ID2D1RenderTarget *pRT = NULL;
IDWriteTextFormat *pTextFormat = NULL;
ID2D1SolidColorBrush *pSolidBrush = NULL;
IWICBitmapEncoder *pEncoder = NULL;
IWICBitmapFrameEncode *pFrameEncode = NULL;
IWICStream *pStream = NULL;
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
reinterpret_cast<void **>(&pWICFactory)
);
if (SUCCEEDED(hr))
{
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
}
if (SUCCEEDED(hr))
{
hr = DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(pDWriteFactory),
reinterpret_cast<IUnknown **>(&pDWriteFactory)
);
}
//
// Create IWICBitmap and RT
//
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateBitmap(
imageWidth,
imageHeight,
GUID_WICPixelFormat32bppBGR,
WICBitmapCacheOnLoad,
&pWICBitmap
);
}
if (SUCCEEDED(hr))
{
hr = pD2DFactory->CreateWicBitmapRenderTarget(
pWICBitmap,
D2D1::RenderTargetProperties(),
&pRT
);
}
if (SUCCEEDED(hr))
{
//
// Create text format
//
static const WCHAR sc_fontName[] = L"Arial";
static const FLOAT sc_fontSize = 20;
hr = pDWriteFactory->CreateTextFormat(
sc_fontName,
NULL,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
sc_fontSize,
L"", //locale
&pTextFormat
);
}
if (SUCCEEDED(hr))
{
pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
//
// Create a path geometry representing an hour glass
//
}
if (SUCCEEDED(hr))
//.........这里部分代码省略.........
示例2: SaveToImageFile
HRESULT SaveToImageFile()
{
HRESULT hr = S_OK;
//
// Create Factories
//
IWICImagingFactory *pWICFactory = NULL;
ID2D1Factory *pD2DFactory = NULL;
IDWriteFactory *pDWriteFactory = NULL;
IWICBitmap *pWICBitmap = NULL;
ID2D1RenderTarget *pRT = NULL;
IDWriteTextFormat *pTextFormat = NULL;
ID2D1PathGeometry *pPathGeometry = NULL;
ID2D1GeometrySink *pSink = NULL;
ID2D1GradientStopCollection *pGradientStops = NULL;
ID2D1LinearGradientBrush *pLGBrush = NULL;
ID2D1SolidColorBrush *pBlackBrush = NULL;
IWICBitmapEncoder *pEncoder = NULL;
IWICBitmapFrameEncode *pFrameEncode = NULL;
IWICStream *pStream = NULL;
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
reinterpret_cast<void **>(&pWICFactory)
);
if (SUCCEEDED(hr))
{
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
}
if (SUCCEEDED(hr))
{
hr = DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(pDWriteFactory),
reinterpret_cast<IUnknown **>(&pDWriteFactory)
);
}
//
// Create IWICBitmap and RT
//
static const UINT sc_bitmapWidth = 640;
static const UINT sc_bitmapHeight = 480;
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateBitmap(
sc_bitmapWidth,
sc_bitmapHeight,
GUID_WICPixelFormat32bppBGR,
WICBitmapCacheOnLoad,
&pWICBitmap
);
}
if (SUCCEEDED(hr))
{
hr = pD2DFactory->CreateWicBitmapRenderTarget(
pWICBitmap,
D2D1::RenderTargetProperties(),
&pRT
);
}
if (SUCCEEDED(hr))
{
//
// Create text format
//
static const WCHAR sc_fontName[] = L"Calibri";
static const FLOAT sc_fontSize = 50;
hr = pDWriteFactory->CreateTextFormat(
sc_fontName,
NULL,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
sc_fontSize,
L"", //locale
&pTextFormat
);
}
if (SUCCEEDED(hr))
{
pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
//
// Create a path geometry representing an hour glass
//.........这里部分代码省略.........
示例3: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = S_OK;
// Create a Direct2D factory.
CHECKHR(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &g_pD2DFactory));
// Create a DirectWrite factory.
CHECKHR(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&g_pDWriteFactory)));
// Create a WIC factory
IWICImagingFactory* pWICFactory = NULL;
CHECKHR(CoInitialize(nullptr));
CHECKHR(CoCreateInstance(CLSID_WICImagingFactory1, nullptr, CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory, (LPVOID*)&pWICFactory));
// Create an IWICBitmap and RT
IWICBitmap* pWICBitmap = NULL;
static const UINT sc_bitmapWidth = 640;
static const UINT sc_bitmapHeight = 480;
CHECKHR(pWICFactory->CreateBitmap(sc_bitmapWidth, sc_bitmapHeight, GUID_WICPixelFormat32bppBGR,
WICBitmapCacheOnLoad,
&pWICBitmap));
// Set the render target type to D2D1_RENDER_TARGET_TYPE_DEFAULT to use software rendering.
CHECKHR(g_pD2DFactory->CreateWicBitmapRenderTarget(
pWICBitmap, D2D1::RenderTargetProperties(), &g_pRenderTarget));
// Create text format and a path geometry representing an hour glass.
IDWriteTextFormat* pTextFormat = NULL;
static const WCHAR sc_fontName[] = L"Calibri";
static const FLOAT sc_fontSize = 50;
CHECKHR(g_pDWriteFactory->CreateTextFormat(
sc_fontName,
NULL,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
sc_fontSize,
L"", //locale
&pTextFormat
));
CHECKHR(pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
CHECKHR(pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER));
// Create a path geometry
ID2D1PathGeometry* pPathGeometry = NULL;
ID2D1GeometrySink* pSink = NULL;
CHECKHR(g_pD2DFactory->CreatePathGeometry(&pPathGeometry));
CHECKHR(pPathGeometry->Open(&pSink));
pSink->SetFillMode(D2D1_FILL_MODE_ALTERNATE);
pSink->BeginFigure(
D2D1::Point2F(0, 0),
D2D1_FIGURE_BEGIN_FILLED
);
pSink->AddLine(D2D1::Point2F(200, 0));
pSink->AddBezier(
D2D1::BezierSegment(
D2D1::Point2F(150, 50),
D2D1::Point2F(150, 150),
D2D1::Point2F(200, 200))
);
pSink->AddLine(D2D1::Point2F(0, 200));
pSink->AddBezier(
D2D1::BezierSegment(
D2D1::Point2F(50, 150),
D2D1::Point2F(50, 50),
D2D1::Point2F(0, 0))
);
pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
CHECKHR(pSink->Close());
// Create GradientStopCollection
ID2D1GradientStopCollection *pGradientStops = NULL;
static const D2D1_GRADIENT_STOP stops[] =
{
{ 0.f, { 0.f, 1.f, 1.f, 1.f } },
{ 1.f, { 0.f, 0.f, 1.f, 1.f } },
};
CHECKHR(g_pRenderTarget->CreateGradientStopCollection(
stops,
ARRAYSIZE(stops),
&pGradientStops
));
//.........这里部分代码省略.........