2010-08-17 2 views
1

저는 Delphi에서 작업하고 있습니다. 내 코드에 bmp.ScanLine[]을 사용하고 있습니다. 내 코드는 다음과 같습니다 :TBitmap.ScanLine [] 실행에 너무 많은 시간이 걸립니다.

bmp := TBitmap.Create; 
    bmp.Height := imgMain.Height; 
    bmp.Width := imgMain.Width; 
    for i := 0 to imgMain.Height - 1 do begin 
     prgb := bmp.ScanLine[i]; 
     p1 := imgMain.ScanLine[i]; 
     for j := 0 to imgMain.Width - 1 do begin 
     //Some code 
     end; 
    end; 

여기서 imgMain은 TBitmap 유형입니다. 내 문제는 내가이 코드를 실행하면, 그것은 내가 잘못 어디 있는지 말해, 라인

prgb := bmp.ScanLine[i]; 
p1 := imgMain.ScanLine[i]; 

하십시오에 너무 많은 시간이 소요입니까?

+1

시간이 얼마나 걸립니까? 너는 무엇을 기대 하느냐? – Harriv

답변

2

흠, 뭔가를 얻을 수 있습니다 (로우 피치 소개, 아래 참조).하지만 너무 많이는 아닙니다. 아마 포인터 증가를 수행하고

// from memory, might need an additional typecast here or there. 

    // will typically be negative 
    scanline0:=imga.scanline[0]; 
    rowpitchimga:=integer(imga.scanline[1])-integer(scanline0); // bytes to jump row. 

    prgb1 :=scanline0; 
    for i:=0 to imgmain.height-1; 
    begin 
     prgbend:=prgb1; 
     inc(prgbend,width); // if prgbend, it will be with sizeof(prgb1^) 
     while(prgb1<prbend) do // smaller then, since prgb1[] is 0 based. 
     begin 
      // do your thing 
      inc(prgb1); 
     end;  
     prgb1:=prgbend; 
     inc(pointer(prgb1),rowpitch-width*sizeof(prgb1^)); // skip alignmentbytes 
     inc(pointer(prgbend),rowpitch); 
    end; 

빠른 이미지를 회전하려면이 같은 일을하는 루틴도 rotating bitmaps. In code 참조 마지막 픽셀의 포인터 값과 비교하는 while 루프에 루프에 대한 변경.

항상 bmps를 할당하는 것은 비용이 많이들 수 있습니다. 특히 큰 경우 반복 할당을 피하기 위해 풀을 사용하십시오.

+0

그렇게하는 방법입니다. 네가 옳아. 64 비트 컴파일러로 코드를 준비하려면 Integer 대신 NativeInt를 사용해야합니다! 트롤 없음 : rowpitchimga : = NativeInt (imga.scanline [1]) - NativeInt (scanline0); Delphi 2007 이전에는 NativeInt = integer 유형을 정의해야했습니다. –

+0

실제로는 ptruint로 정의되며 이미 64 비트에서 실행됩니다. 그것은 원래 Free Pascal을 사용하여 개발되었습니다. 왜 엠바 카데로가 다른 식별자를 선택했는지 모르겠다. –

+0

안녕하세요 @ 마르코, 늦게 답장을 드려 죄송합니다. 예, 이것이 해결책이 될 수 있습니다. 필자가 관찰 한 또 하나의 점은''p1 : = imgMain.Scanline [i];라고 쓰면 그리 많은 시간이 걸리지 않는다는 것입니다. 그래서, 그것은 단지'prgb : = bmp.Scanline [i];'에서 시간을들입니다. 여기서 imgMain은 TBitmap.Assign();을 사용하여 TImage 비트 맵에서 복사 한 비트 맵입니다. – Himadri

관련 문제