typedef struct _D3DCOLORVALUE { float r; //红色分量值,范围0-1 float g; //绿色分量值,范围0-1 float b; //蓝色分量值,范围0-1 float a; //alpha分量值(透明度),范围0-1 } D3DCOLORVALUE;
其中,四个属性的取值范围是0-1。
D2D1::ColorF(0.0f, 0.0f, 0.0f, 1.0f); //rgba形式 D2D1::ColorF(0x000000, 1.0f); //UINT32形式 D2D1::ColorF(D2D1::ColorF::Pink, 1.0f); //Enum形式特定值
//1初始化IWICImagingFactory IWICImagingFactory *pIWICFactory; CoInitialize(NULL); CoCreateIstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pIWICFactory) ); ID2D1Bitmap *pBitmap; IWICBitmapDecoder *pDecoder; IWICBitmapFrameDecode *pSource; IWICStream *pStream; IWICFormatConverter *pConverter; IWICBitmapScaler *pScaler; //2初始化IWICBitmapDecoder pIWICFactory->CreateDecoderFromFilename( "filename", //修改为图片的路径名 NULL, GENERIC_READ, WICDecodeMetadataCacheOnload, &pDecoder ); //3初始化IWICBitmapFrameDecode pDecoder->GetFrame(0, &pSource);
//4初始化IWICBitmapScaler pIWICFactory->CreateBitmapScaler(&pScaler); pScaler->Initialize( pSource, width, //缩放至width宽度 height, //缩放至height高度 WICBitmapInterpolationModeCubic ); //4初始化IWICFormatConverter pIWICFactory->CreateFormatConverter(&pConverter); pConverter->Initialize( pScaler, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeMedianCut ); //5从WIC中加载位图 pRenderTarget->CreateBitmapFromWicBitmap( pConvert, NULL, &pBitmap ); //6释放临时对象 XXXXX->Release();
ID2D1SolidColorBrush *pscBrush; //创建单色画刷 RenderTarget->CreateSolidColorBrush( D2D1::ColorF(0, 1.0f), &pscBrush );
ID2D1LinearGradientBrush *plgBrush; ID2D1GradientStopCollection *pgsCollection; //创建渐变节点数组 D2D1_FRADIENT_STOP gradientStops[2]; gradientStops[0] = {0.0f, D2D1::ColorF(0, 1.0f)}; gradientStops[1] = {1.0f, D2D1::ColorF(0xffffff, 1.0f)}; //创建渐变条(这一部分可以想象成ps中的那个渐变) RenderTarget->CreateGradientStopCollection( gradientStops, //渐变颜色点信息 2, //渐变颜色点数量 D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, &pGsCollection ); //创建渐变刷 RenderTarget->CreateLinearGradientBrush( LinearGradientBrushProperties( D2D1::Point2F(0, 0), //渐变线起始点(窗口坐标) D2D1::Point2F(150, 150) //渐变线终点(窗口坐标) ), pgsCollection, &plgBrush );
g_pTarget->CreateRadialGradientBrush( RadialGradientBrushProperties( Point2F(20,20), //颜色中心 Point2F(0, 0), //颜色偏离中心 20, //颜色x轴 20 //颜色y轴 ), g_pGsCollection, &g_pRgBrush );
//使用WIC从文件中加载资源后 pRenderTarget->CreateBitmapBrush(pBitmap, &BitmapBrush);
pRenderTarget->BeginDraw(); pRenderTarget->FillRectangle(&rect, pxxxBrush); pRenderTarget->DrawRectangle(&rect, pxxxBrush); pRenderTarget->EndDraw();
下一期将学习位图刷和位图的更多用法。
原文:https://www.cnblogs.com/halation/p/11621426.html