2010-04-02 20 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;