draw JPEG (windows)[ing..]

[20110122_2324]  发现资料看到一定程度就不记随笔了,,因为开始大量查找内容,,觉得很点睛的内容已经没了.


[20110123_2315]  CopyPalette,并非所有 图像帧 都有调色板.   4位图有, 16, 32位图没有.

[20110123_2315]  GetPixelFormat,能获得图像格式. 但是GUID编码, 非int,string等格式, 无法直接使用.

            GetSize能获得图像width, length.


 Solution

WIC sample          http://msdn.microsoft.com/en-us/library/ee720055(v=VS.85).aspx

JPEG Overview           http://msdn.microsoft.com/en-us/library/gg430026(vs.85).aspx#_imagequality

Decoding Overview         http://msdn.microsoft.com/en-us/library/ee719870(v=vs.85).aspx

Bitmap Sources Overview  http://msdn.microsoft.com/en-us/library/ee719656(v=vs.85).aspx#_bitmapsources

找到好链接, 很快就能学会应用了. 

WIC Sample是最后找到的.但问题是解决最直接的, 直接实例, 再结合前面的Define学快很多.

 

Key Function

 

IWICBitmapScaler        拉伸图像

IWICFormatConverter    转换图像调色板颜色, 通道颜色.

QueryInterface       对象转存

 pConverter->QueryInterface(IID_PPV_ARGS(ppToRenderBitmapSource));

 


Graphics Class  [GDI+]

结果: 图片质量低

http://msdn.microsoft.com/en-us/library/ms534453(v=VS.85).aspx

// 代码只是示意流程, 不能直接使用.
#include <windows.h>
#include
<gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;

INT main()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(
&gdiplusToken, &gdiplusStartupInput, NULL);

Image
* image = new Image(L"D:\\Project\\c++\\lee_win32_2\\JPEG.jpg");
Graphics graphics(hdc);

  graphics.DrawImage(image,
10, 10);
graphics.DrawImage(image,
0.0f, 0.0f, 0.0f, 0.0f, 300.0f, 1000.0f, UnitPixel);

delete image;
GdiplusShutdown(gdiplusToken);
return 0;
}

ing..

在找如何提升Graphics解压JPEG质量的参数, 以上流程显示的图片, 实在非常不清楚.

 

 

GSetDIBitsToDevice, StretchDIB  [GDI]

正在跟踪, 还没解决.

http://msdn.microsoft.com/en-us/library/dd145131(v=vs.85).aspx

//
// pvJpgImage points to a buffer containing the JPEG image
// nJpgImageSize is the size of the buffer
// ulJpgWidth is the width of the JPEG image
// ulJpgHeight is the height of the JPEG image
//

//
// Check if CHECKJPEGFORMAT is supported (device has JPEG support)
// and use it to verify that device can handle the JPEG image.
//

ul
= CHECKJPEGFORMAT;

if (
// Check if CHECKJPEGFORMAT exists:

(ExtEscape(hdc, QUERYESCSUPPORT,
sizeof(ul), &ul, 0, 0) > 0) &&

// Check if CHECKJPEGFORMAT executed without error:

(ExtEscape(hdc, CHECKJPEGFORMAT,
pvJpgImage, nJpgImageSize,
sizeof(ul), &ul) > 0) &&

// Check status code returned by CHECKJPEGFORMAT:

(ul
== 1)
)
{
//
// Initialize the BITMAPINFO.
//

memset(
&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize
= sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth
= ulJpgWidth;
bmi.bmiHeader.biHeight
= -ulJpgHeight; // top-down image
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount
= 0;
bmi.bmiHeader.biCompression
= BI_JPEG;
bmi.bmiHeader.biSizeImage
= nJpgImageSize;

//
// Do the SetDIBitsToDevice.
//

iRet
= SetDIBitsToDevice(hdc,
ulDstX, ulDstY,
ulDstWidth, ulDstHeight,
0, 0,
0, ulJpgHeight,
pvJpgImage,
&bmi,
DIB_RGB_COLORS);

if (iRet == GDI_ERROR)
return FALSE;
}
else
{
//
// Decompress image into a DIB and call SetDIBitsToDevice
// with the DIB instead.
//
}

ing..

[20110117_1100]  :  由此证实可以用GDI打印, 问题是有4个参数还没搞清楚怎么获得.

[20110117_1222]  :  JPEG从文件读入后, 需要先解码, 再使用.

 

 

The Windows Imaging Component (WIC) is an extensible platform that provides low-level API for digital images.

 

Introduction

BitMap decoders  : 可以看作一个容器.  包装着压缩图像.
global property    : 它同时有很多属性. 包括缩略图, 媒体数据等.  但并非所有压缩图像都支持.
IWICBitmapDecoder : enter the global property.

IWICBitmapFrameDecode

Native Bitmap Decoders

IWICBitmapDecoder interface  本地图片解压 :  支持网络图片, 高清动态图片,BMP,GIF,ICO,JPEG,PNG,TIFF,HD photo.

global level: 可能不支持缩略图等属性 

frame level: 但frame level支持


 

MethodDescription
CopyPalette

调色板

GetColorContexts

颜色关系

GetContainerFormat

容器格式(GUID)

GetDecoderInfo

WICBitmapDecoderInfo

GetFrame

某一帧  

GetFrameCount

总帧数  

GetMetadataQueryReader

 

GetPreview

预览

GetThumbnail

缩略图

Initialize

 

QueryCapability

ImageQuality Option

图片质量

BitmapTransform Option

图片旋转

Bitmap Sources

位图是WIC的一部分, 由一组pixel点集组成.  
可以是复杂图像中独立的一帧, 或bitmapsource转换的结果.

IWIBitmapSource接口是很多WIC接口的基础, 例如IWICBbitmapFrameDecode, IWIBitmapFlipRotator.

 

 

CopyPixels Method

 

拷贝图像是 图形解压2个重要过程中的1个.   

它通过算法, 解压JPEG图片, 图片可能在disk,memory中, 甚至解压一个复杂的渐变.

算法完全依赖于CopyPixels接口的实现.

 

 

IWICBitmap Interface

当像素需要被移动到一个新位置, CopyPixels是最有效的方法.
Because of to the internal memory representation implied by the IWICBitmap, in-place modification and processing using the Lock is more efficient than CopyPixels, usually reducing to a simple pointer access directly into the memory owned by the bitmap rather than a as a copy. This is contrasted to procedural bitmaps which implement only CopyPixels because there is no internal memory representation and one would need to be created on demand to satisfy a call to Lock.
因为IWICBitmap内部有内存, 所以使用 Lock就地进行修改处理会比CopyPixels高效, 
通常应该减少简单指针直接进入bitmap拥有的内存相对copy,   这使得只有CopyPixels接口时很困惑, 因为没有内部内存和需要创建一个内存去Lock为了安全访问.

 

posted on 2011-01-17 10:56  oleeceo  阅读(661)  评论(0)    收藏  举报

导航