2010-04-02 19 views
26

我有TWICImage,IWicBitmap和IWicBitmapSource,可以很好地显示所有支持的图形文件格式,允许旋转,水平翻转,翻转垂直,缩放和剪切。所有这些似乎工作得很好,我可以得到WicImages像素格式,但我不知道如何更改或设置TWicImage的像素格式。如何在Delphi 2010中更改TWICImage的像素格式

我创建了一个对话框来返回WICPixelFormatGUID以用作转换的像素格式。

任何人都可以共享一些代码演示如何用IWICColorTransform或其他Wincodec方法更改WicImage的像素格式吗?

比尔

到2011年,现在它的中间......所以对那些可能想知道,我想这和它似乎工作(它使用TcxImage由Developer Express公司,但我怀疑TImage中也能发挥作用) :

procedure TForm1.N16bitBGR1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat16bppBGR555, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N16bitGray1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat16bppGray, WICBitmapDitherTypeSolid, nil, 0, 
     WICBitmapPaletteTypeFixedGray16); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N24bitGBB1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N2bitIndexed1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat2bppIndexed, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N32bitGray1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat32bppGrayFloat, WICBitmapDitherTypeSolid, nil, 0, 
     WICBitmapPaletteTypeFixedGray256); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N32bitGRBA1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N4bitIndexed1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat4bppIndexed, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N8bitGray1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat8bppGray, WICBitmapDitherTypeSolid, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N8bitIndexed1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeFixedGray256); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 
+1

+1 ,无论如何,你可以简单地使用['WICConvertBitmapSource'](http://msdn.microsoft.com/en-us/library/windows/desktop/ee719819(v = vs.85).aspx)函数而不需要格式转换器为此。 – TLama 2012-09-11 15:34:29

+1

嗨,比尔,你的回答在没有答案的德尔菲问题的顶部。如果我正确地读了它,你解决它并把你的答案放到你的问题中。你可以将答案放入答案部分并接受它吗? – bummi 2014-09-27 20:39:21

+0

现在11月份,这还没有完成,我建议有人为他做这件事,并附有归属地。 – 2014-11-21 14:29:42

回答

2

Bummi和Warren P问我发布了我前一段时间添加的答案。下面是答案:

对于那些可能想知道,我想这和它似乎工作(它使用TcxImage由Developer Express公司,但我怀疑TImage中也能发挥作用):

procedure TForm1.N16bitBGR1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat16bppBGR555, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N16bitGray1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat16bppGray, WICBitmapDitherTypeSolid, nil, 0, 
     WICBitmapPaletteTypeFixedGray16); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N24bitGBB1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N2bitIndexed1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat2bppIndexed, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N32bitGray1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat32bppGrayFloat, WICBitmapDitherTypeSolid, nil, 0, 
     WICBitmapPaletteTypeFixedGray256); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N32bitGRBA1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N4bitIndexed1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat4bppIndexed, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N8bitGray1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat8bppGray, WICBitmapDitherTypeSolid, nil, 0, 
     WICBitmapPaletteTypeMedianCut); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end; 

procedure TForm1.N8bitIndexed1Click(Sender: TObject); 
var 
    wicImg: TWICImage; 
    wicBitmap: IWICBitmap; 
    iBmpSource: IWICBitmapSource; 
    puiWidth, puiHeight: UINT; 
    iConverter: IWICFormatConverter; 
begin 
    if cxImage1.Picture.Graphic is TWICImage then 
    begin 
    Screen.Cursor := crHourGlass; 
    try 
     wicImg := TWICImage(cxImage1.Picture.Graphic); 
     wicImg.ImagingFactory.CreateFormatConverter(iConverter); 
     iBmpSource := wicImg.Handle as IWICBitmapSource; 
     iBmpSource.GetSize(puiWidth, puiHeight); 
     iConverter.Initialize(iBmpSource, GUID_WICPixelFormat8bppIndexed, WICBitmapDitherTypeNone, nil, 0, 
     WICBitmapPaletteTypeFixedGray256); 
     wicImg.ImagingFactory.CreateBitmapFromSourceRect(iConverter, 0, 0, puiWidth, puiHeight, wicBitmap); 
     if Assigned(wicBitmap) then 
     wicImg.Handle := wicBitmap; 
     cxImage1.Repaint; 
     cxImage1.Update; 
     cxImage1.Invalidate; 
     dxStatusBar1.Panels[ 0 ].Text := ExtractFileDir(AFilename); 
     dxStatusBar1.Panels[ 1 ].Text := ExtractFileName(AFilename); 
     dxStatusBar1.Panels[ 2 ].Text := 'Width: ' + IntToStr(WICImageWidth(cxImage1)); 
     dxStatusBar1.Panels[ 3 ].Text := 'Height: ' + IntToStr(WICImageHeight(cxImage1)); 
     dxStatusBar1.Panels[ 4 ].Text := 'Pixel Format: ' + WICGetPixelFormat(cxImage1); 
    finally 
     Screen.Cursor := crDefault; 
    end; 
    end; 
end;