gpt4 book ai didi

delphi - 如何在 Delphi 2010 中更改 TWICImage 的像素格式

转载 作者:行者123 更新时间:2023-12-03 14:33:48 28 4
gpt4 key购买 nike

我有一个 TWicImage、IWicBitmap 和一个 IWicBitmapSource,它们可以很好地显示所有支持的图形文件格式,允许旋转、水平翻转、垂直翻转、缩放和剪切。所有这些似乎都运行良好,我可以获得 WicImages 像素格式,但我不知道如何更改或设置 TWicImage 的像素格式。

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

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

比尔

现在已经是 2011 年中期了...对于那些可能想知道的人来说,我尝试过这个,它似乎有效(它使用 Developer Express 的 TcxImage,但我怀疑 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;

最佳答案

Bummi 和 Warren P 要求我发布我之前添加的答案。答案如下:

对于那些可能想知道的人,我尝试了这个,它似乎有效(它使用 Developer Express 的 TcxImage,但我怀疑 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;

关于delphi - 如何在 Delphi 2010 中更改 TWICImage 的像素格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2569230/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com