如何读取 WIC 图像中的像素
下面的代码(来自此线程:如何在 Canon 文件上使用 Delphi 2010 的新 WIC 功能?)将 WIC 图像打开为位图。
但是,如果 WIC 像素值的动态范围很大,则此代码会丢失大量信息,因为它必须将宽动态范围缩放到位图像素可以容纳的低范围。
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;
谁能向我展示示例代码,让我直接从 TWICImage 读取像素值,这样我就可以访问图像数据而不会丢失信息?我需要每个像素的强度(灰度)值,如果不能直接获得,也许可以从 RGB 值计算出来?
像这样的东西:
var
PixelValue: Integer; // Grayscale
for Row := 0 to WIC.Width do
for Col := 0 to WIC.Height
PixelValue := WIC.GetPixelValue(Row, Col);
The code below (from this thread: How to use Delphi 2010's new WIC capability on Canon files?) opens a WIC image into a BitMap.
However, if the dynamic range of WIC pixel values is large, this code loses a lot of information, since it has to scale the wide dynamic range into the low range that a Bitmap pixel can accommodate.
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;
Can anyone show me sample code that would let me read the pixel values directly from the TWICImage, so I can access the image data without losing information? I need the intensity (gray scale) values of each pixel which perhaps can be calculated from the RGB values if not directly available?
Something like:
var
PixelValue: Integer; // Grayscale
for Row := 0 to WIC.Width do
for Col := 0 to WIC.Height
PixelValue := WIC.GetPixelValue(Row, Col);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够将 TWICImage 分配给 TBitmap,然后访问位图的 Pixels 或 ScanLine 属性以获取像素数据。就像加载 JPEG 时所做的那样。
例如(未经测试的伪代码)
You should be able to
assign()
the TWICImage to a TBitmap, and then access the bitmap's Pixels or ScanLine property to get at the pixel data. Much like you'd do when loading a JPEG.For example (untested pseudocode)