Форум: "Начинающим";
Текущий архив: 2009.12.27;
Скачать: [xml.tar.bz2];
Внизsmoothresize Найти похожие ветки
← →
Тимофей123 (2009-11-10 16:10) [0]данной процедурой меняю размер
procedure SmoothResize(Width, Height : integer; S,D : TBitmap);
type
TRGBArray = array[Word] of TRGBTriple;
pRGBArray = ^TRGBArray;
var
x, y: Integer;
xP, yP: Integer;
Mx, My: Integer;
SrcLine1, SrcLine2: pRGBArray;
t3: Integer;
z, z2, iz2: Integer;
DstLine: pRGBArray;
DstGap: Integer;
w1, w2, w3, w4: Integer;
begin
S.PixelFormat := pf24Bit;
D.PixelFormat := pf24Bit;
if Width*Height=0 then
begin
D.Assign(S);
exit;
end;
D.Width:=Width;
D.Height:=Height;
if (S.Width = D.Width) and (S.Height = D.Height) then
D.Assign(S)
else
begin
DstLine := D.ScanLine[0];
DstGap := Integer(D.ScanLine[1]) - Integer(DstLine);
Mx := MulDiv(S.Width+1, $10000, D.Width);
My := MulDiv(S.Height+1, $10000, D.Height);
yP := 0;
for y := 0 to pred(D.Height) do
begin
xP := 0;
SrcLine1 := S.ScanLine[yP shr 16];
if (yP shr 16 < pred(S.Height))and(Y<>D.Height-1) then
SrcLine2 := S.ScanLine[succ(yP shr 16)]
else
begin
SrcLine1 := S.ScanLine[S.Height-2];
SrcLine2 := S.ScanLine[S.Height-1];
end;
z2 := succ(yP and $FFFF);
iz2 := succ((not yp) and $FFFF);
for x := 0 to pred(D.Width) do
begin
t3 := xP shr 16;
z := xP and $FFFF;
w2 := MulDiv(z, iz2, $10000);
w1 := iz2 - w2;
w4 := MulDiv(z, z2, $10000);
w3 := z2 - w4;
if (t3>=S.Width-1)or(x=D.Width-1) then
t3:=S.Width-2;
DstLine[x].rgbtRed := (SrcLine1[t3].rgbtRed * w1 +
SrcLine1[t3 + 1].rgbtRed * w2 + SrcLine2[t3].rgbtRed * w3 + SrcLine2[t3 + 1].rgbtRed * w4) shr 16;
DstLine[x].rgbtGreen := (SrcLine1[t3].rgbtGreen * w1 + SrcLine1[t3 + 1].rgbtGreen * w2 +
SrcLine2[t3].rgbtGreen * w3 + SrcLine2[t3 + 1].rgbtGreen * w4) shr 16;
DstLine[x].rgbtBlue := (SrcLine1[t3].rgbtBlue * w1 +
SrcLine1[t3 + 1].rgbtBlue * w2 +SrcLine2[t3].rgbtBlue * w3 + SrcLine2[t3 + 1].rgbtBlue * w4) shr 16;
Inc(xP, Mx);
end; {for}
Inc(yP, My);
DstLine := pRGBArray(Integer(DstLine) + DstGap);
end; {for}
end; {if}
end; {SmoothResize}
Вызываю так:
var jpg:TJpegImage;
bm:TBitmap;
begin
try
jpg:=TJpegImage.Create;
bm:=TBitmap.Create;
jpg.LoadFromFile(GetCurrentDir+"\4.jpg");
jpg.DIBNeeded;
bm.Assign(jpg);
SmoothResize(100,100,bm,img1.Picture.Bitmap);
jpg.Free;
bm.Free;
except
end;
Почему то вылезает ошибка scan line index out of range.
← →
Сергей М. © (2009-11-10 16:13) [1]А что сказал по этому поводу отладчик ?
← →
Тимофей123 (2009-11-10 16:30) [2]не умею пользоваться отладчиком.
По сути: у меня есьт bmp, в ней находится изображение, мне нужно чтобы это изображение увеличилось в размерах раза в 2, затем поместить обратно в эту bmp. Но с реализацией проблемы:(
← →
Amoeba © (2009-11-10 16:41) [3]
> Тимофей123 (10.11.09 16:30) [2]
>
> не умею пользоваться отладчиком.
Учитесь, иначе далеко не уедете.
← →
Тимофей123 (2009-11-10 16:43) [4]bm:=TBitmap.Create;
bm.LoadFromFile(GetCurrentDir+"\4.bmp");
SmoothResize(200,100,bm,img1.Picture.Bitmap);
bm.SaveToFile(GetCurrentDir+"\xz.bmp"); эту строку уже не обрабатывает, я та к понял что из за ошибка про scan line
bm.Free;
except
end;
← →
Тимофей123 (2009-11-10 16:47) [5]когда y = 94 то вот здесь
for y := 0 to pred(D.Height) do
begin
xP := 0;
SrcLine1 := S.ScanLine[yP shr 16]; на этом месте вылезает ошибка про scan line
вызываю так
SmoothResize(100,100,bm,img1.Picture.Bitmap);
← →
Сергей М. © (2009-11-10 17:01) [6]
> не умею пользоваться отладчиком
Это не оправдание.
Учись пользоваться.
← →
Тимофей123 (2009-11-10 17:47) [7]согласен, я и не оправдывался:)
← →
Sapersky (2009-11-10 18:16) [8]Используй StretchBlt в режиме Halftone. Он несколько медленнее, но вряд ли ты это заметишь. Зато качество лучше при сильном уменьшении. И не вылетает :)
Страницы: 1 вся ветка
Форум: "Начинающим";
Текущий архив: 2009.12.27;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.008 c