我将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",不知为什么提示扫描越界?请高手帮助

解决方案 »

  1.   

    Image1.Picture.BItmap.PixelFormat:=pf24bit;
    3个字节对应一个象素,如果你不吧内存中的位图格式化成24位图,除非恰巧原来的就是24位图,否则当然会报错了.
      

  2.   

    任久提示scan line index out of range扫描越界,不行啊!为什么?没有高手了吗?
      

  3.   

    for i:=0 to image1.Picture.Height-1 do
    应该是Image1.Piture.Bitmap.Height
    image1.Picture.Width-1 应该是Image1.Picture.Bitmap.Width -1不要以为Bitmap和JPEG是一样的,如果你用JPEG,那么Bitmap没有用。
    用Canvas,或者用TJPEGImage来转换成Bitmap再处理。
      

  4.   

    bitmap格式是不是已经就是把jpg的每个象素转换成了rbg值?
      

  5.   

    那可以把jpg转换成bitmap格式图片代码给我看看吗?我忘记了!
      

  6.   

    肯定创建了喔!
    //将jpeg文件加载并付给Bitmap对象
    procedure Tform1.GetRGBBitmap(Filename:string);
    var
      Jpegmap:TJPEGImage;
    begin
      Jpegmap:=TjpegImage.Create;
      try
        Jpegmap.LoadFromFile(FileName);    //加载jpeg文件
        image1.Picture.Bitmap.PixelFormat:=Pf24Bit;
        image1.Picture.bitmap.Assign (JpegMap);
      finally
        Jpegmap.free;
      end;
    end;
    //象素点转换成RGB值
    procedure TForm1.rgbchange(ImgRGB:TRGBArray);
    Var
      Row:pRGBArray;
      i,j,n:Integer;
    begin
    n:=0;
    for i:=0 to image1.Picture.bitmap.Height-1 do
    begin
      Image1.Picture.BItmap.PixelFormat:=pf24bit;
      Row:=Image1.Picture.bitmap.ScanLine[i];
      for j:=0 to image1.Picture.bitmap.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;
    我的代码!看有什么错误?
      

  7.   

    Row定义的是个类型指针,指针当然要分配内存,直接用数组
      

  8.   

    错了,刚才没注意看pRGBArray的定义,可能是长乘宽超过了数组的范围!报什么错?
      

  9.   

    我的定义:type
      tagRGBTRIPLE = packed record
       rgbtBlue: Byte;
       rgbtGreen: Byte;
       rgbtRed: Byte;
      end;
        TRGBTriple = tagRGBTRIPLE;
        TRGBArray  = ARRAY[0..65534] OF TRGBTriple;
        pRGBArray = ^TRGBArray;
    在98下报错居然是说"该程序执行了非法操作,即将关闭"然后直接就推出了,根本无法运行下去,而且没有其他任何提示,让我不知何去何从!@
      

  10.   

    而在xp下运行提示"access violation at 0x38474233:read of address 0x38474233"
    好像的确是内存读取时有问题!那怎么解决呢?多谢高手ehom多次帮助!不甚感激!在上面初始化时我加了一条new(row)来初始化指针变量,但是没有好转!难道要把new加到for循环里面?每次都声请一个?我觉得不会把!那用数组怎么表达呢?给点代码我看看吧!
      

  11.   

    高手们!help me!等了好多天了!无法解决!
      

  12.   

    Row:=Image1.Picture.bitmap.ScanLine[i];
    这里已经将指针指向了一个地址,不用分配内存看看也知道,0..65534这个范围还是很小的,长乘宽的结果很容易超过范围
      

  13.   

    同意ehom的看法!设为640*480的大小吧!比较妥当!