Direct2D Intro - Scale a Bitmap Source
2016-04-13 16:48
543 查看
https://msdn.microsoft.com/en-us/library/windows/desktop/ee719664(v=vs.85).aspx
This topic demonstrates how to scale an
IWICBitmapSource using the
IWICBitmapScaler component.
To scale a bitmap source
Create an
IWICImagingFactory object to create Windows Imaging Component (WIC) objects.
C++
Copy
Use the
CreateDecoderFromFilename method to create an
IWICBitmapDecoder from an image file.
C++
Copy
Get the first
IWICBitmapFrameDecode of the image.
C++
Copy
The JPEG file format only supports a single frame. Because the file in this example is a JPEG file, the first frame (
How to Retrieve the Frames of an Image for accessing each frame of the image.
Create the
IWICBitmapScaler to use for the image scaling.
C++
Copy
Initialize the scaler object with the image data of the bitmap frame at half the size.
C++
Copy
Draw or process the scaled bitmap source.
The following illustration demonstrates imaging scaling. The original image on the left is 200 x 130 pixels. The image on the right is the original image scaled to half the size.
This topic demonstrates how to scale an
IWICBitmapSource using the
IWICBitmapScaler component.
To scale a bitmap source
Create an
IWICImagingFactory object to create Windows Imaging Component (WIC) objects.
C++
Copy
// Create WIC factory hr = CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_pIWICFactory) );
Use the
CreateDecoderFromFilename method to create an
IWICBitmapDecoder from an image file.
C++
Copy
HRESULT hr = S_OK; IWICBitmapDecoder *pIDecoder = NULL; IWICBitmapFrameDecode *pIDecoderFrame = NULL; IWICBitmapScaler *pIScaler = NULL; hr = m_pIWICFactory->CreateDecoderFromFilename( L"turtle.jpg", // Image to be decoded NULL, // Do not prefer a particular vendor GENERIC_READ, // Desired read access to the file WICDecodeMetadataCacheOnDemand, // Cache metadata when needed &pIDecoder // Pointer to the decoder );
Get the first
IWICBitmapFrameDecode of the image.
C++
Copy
// Retrieve the first bitmap frame. if (SUCCEEDED(hr)) { hr = pIDecoder->GetFrame(0, &pIDecoderFrame); }
The JPEG file format only supports a single frame. Because the file in this example is a JPEG file, the first frame (
0) is used. For image formats that have multiple frames, see
How to Retrieve the Frames of an Image for accessing each frame of the image.
Create the
IWICBitmapScaler to use for the image scaling.
C++
Copy
// Create the scaler. if (SUCCEEDED(hr)) { hr = m_pIWICFactory->CreateBitmapScaler(&pIScaler); }
Initialize the scaler object with the image data of the bitmap frame at half the size.
C++
Copy
// Initialize the scaler to half the size of the original source. if (SUCCEEDED(hr)) { hr = pIScaler->Initialize( pIDecoderFrame, // Bitmap source to scale. uiWidth/2, // Scale width to half of original. uiHeight/2, // Scale height to half of original. WICBitmapInterpolationModeFant); // Use Fant mode interpolation. }
Draw or process the scaled bitmap source.
The following illustration demonstrates imaging scaling. The original image on the left is 200 x 130 pixels. The image on the right is the original image scaled to half the size.
相关文章推荐
- hive 的表操作问题 hive中简单介绍分区表
- XPlane android 2D手游开发实战
- 第四次作业
- Struts2利用iText导出word文档
- JAVA 接口
- Python 中用 Ctrl+C 终止多线程程序的问题解决
- 《Android源码设计模式》读书笔记 (24) 第24章 桥接模式
- params详解
- shell各类脚本
- 集群监控
- 如何在iOS上创建矢量图形 画云 和 拼图块
- 二叉树先中后遍历
- bootstrap
- 数组
- mybatis 使用场景
- Spring和Mybatis整合,配置文件
- Repeater 横向显示数据
- Android Wear SDK 中文 ---- 创建表盘 [Creating Watch Faces]
- 写技术文章必备的几个小工具
- 学习OpenGL(五)绘制多边形