2010-04-02 17 views
26

Ho un TWicImage, IWicBitmap e un IWicBitmapSource che funziona bene per visualizzare tutti i formati di file grafici supportati, consente Rotazione, Rifletti orizzontale, Rifletti verticale, Ridimensionamento e ritaglio. Tutti questi sembrano funzionare bene e posso ottenere il pixelformat di WicImages, ma non riesco a capire come modificare o impostare il pixelformat di TWicImage.Come modificare il pixelformat di un TWICImage in Delphi 2010

Ho creato una finestra di dialogo per restituire WICPixelFormatGUID da utilizzare come pixelformat per la trasformazione.

Qualcuno può condividere qualche codice che dimostra come modificare il pixelformat di un WicImage con IWICColorTransform o un altro metodo Wincodec?

Bill

sua metà 2011 ora ... quindi per coloro che possono desiderare di sapere Ho provato questo e sembra funzionare (usa TcxImage da Developer Express, ma ho il sospetto TImage funzionerà pure) :

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 , comunque, puoi semplicemente usare la funzione ['WICConvertBitmapSource'] (http://msdn.microsoft.com/en-us/library/windows/desktop/ee719819 (v = vs.85) .aspx) senza bisogno di formattazione convertitore per questo. – TLama

+1

Ciao Bill, la tua risposta nella parte superiore delle domande Delphi senza risposta. Se l'ho letto correttamente, l'hai risolto e hai inserito la tua risposta nella tua domanda. Potresti inserire la risposta nella sezione di risposta e accettarla? – bummi

+0

Ora è novembre e non è fatto, suggerisco che qualcuno lo faccia per lui, con attribuzione. –

risposta

2

Bummi e Warren P hanno chiesto di pubblicare la risposta che avevo aggiunto qualche tempo fa. Ecco la risposta:

Per coloro che possono desiderare di sapere Ho provato questo e sembra funzionare (usa TcxImage da Developer Express, ma ho il sospetto TImage funzionerà pure):

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; 
Problemi correlati