问题
Does anyone know of some sample code that shows how Delphi 2010 can read RAW files using its new COM interface to WIC?
I want to read Canon RAW images and then access specific pixels...
回答1:
This is the simplest usage:
procedure TForm116.Button1Click(Sender: TObject);
var
WIC: TWICImage;
begin
WIC := TWICImage.Create;
try
WIC.LoadFromFile('MyFilename.raw');
Image1.Picture.Graphic.Assign(WIC);
finally
WIC.Free;
end;
end;
There are many, many, many different types of "raw" image file formats, so there is no telling if WIC will be able to handle it.
回答2:
TPicture is very tricky to work with, when you access the Graphic property it does not check anything. To make Nick's code work you can force the Picture to create a bitmap first:
Image1.Picture.Bitmap;
Image1.Picture.Graphic.Assign(WIC);
It would be nice if the TPicture class was more succesful in hiding its implementation details :-)
回答3:
Nick's answer was correct after all! I went back looked more closely and found the exception was occurring on the Assign statement ... because the TImage on my form didn't have a Picture! Assigning any picture in the IDE Object Inspector or initializing it in a way similar to my code below made it work great!
The code below will convert a RAW file to a BMP file. I haven't worked much with images, so I'm not absolutely certain that the code below is correct, but it seems to be working. Feedback welcome.
Reminder to other developers: my earlier comment above has links to a great source of sample RAW files and codecs. These are invaluable.
Thanks, Nick, AND Embarcadero!!!
procedure TForm1.Button1Click(Sender: TObject);
var
WIC: TWICImage;
BMP: TBitMap;
begin
WIC := TWICImage.Create;
BMP := TBitMap.Create;
try
WIC.LoadFromFile('MyFileName.Raw');
BMP.Assign(WIC);
BMP.SaveToFile('MyFilename.bmp');
finally
WIC.Free;
BMP.Free;
end;
end;
回答4:
Having loaded the Canon RAW Codec, rc170upd_7l.exe, from http://www.usa.canon.com/cusa/windows_vista/cameras/eos_slr_camera_systems/canon_raw_codec_software#DriversAndSoftware, this displays an image in Delphi 2010 on XP SP3:
var
WIC: TWICImage;
begin
WIC := TWICImage.Create;
try
WIC.LoadFromFile('IMG_0201.CR2'); // WIC.ImageFormat reports wifOther
Img1.Picture.Assign(WIC);
finally
WIC.Free;
end;
end;
来源:https://stackoverflow.com/questions/2405899/how-to-use-delphi-2010s-new-wic-capability-on-canon-files