我将jpg图片转换成一个每个象素点由RGB值组成的二维数组,代码如下:
type
tagRGBTRIPLE = packed record
rgbtBlue: Byte;
rgbtGreen: Byte;
rgbtRed: Byte;
end;
TRGBTriple = tagRGBTRIPLE;
TRGBArray = ARRAY[0..65534] OF TRGBTriple;
pRGBArray = ^TRGBArray;
procedure TForm1.rgbchange(ImgRGB:TRGBArray);
Var
Row:pRGBArray;
i,j,n:Integer;
begin
n:=0;
for i:=0 to image1.Picture.Height-1 do
begin
Row:=Image1.Picture.Bitmap.ScanLine[i];
for j:=0 to image1.Picture.Width-1 do
begin
ImgRGB[n].rgbtRed:=Row^[j].rgbtRed;
ImgRGB[n].rgbtGreen:=Row^[j].rgbtGreen;
ImgRGB[n].rgbtBlue:=Row^[j].rgbtBlue;
inc(n);
end;
end;
end;
但是运行后提示"scan line index out of range",不知为什么提示扫描越界?请高手帮助
Row:=Image1.Picture.bitmap.ScanLine[i];
这里已经将指针指向了一个地址,不用分配内存
看看也知道,0..65534这个范围还是很小的,长乘宽的结果很容易超过范围
同意ehom的看法!设为640*480的大小吧!比较妥当!