开发者

How to use Delphi 2010's new WIC capability on Canon files?

开发者 https://www.devze.com 2022-12-22 19:50 出处:网络
Does anyone know of some sample code th开发者_如何学JAVAat shows how Delphi 2010 can read RAW files using its new COM interface to WIC?

Does anyone know of some sample code th开发者_如何学JAVAat 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...


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.


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 :-)


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;


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;  
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号