Redimensionar Imagem
Olá pessoal, eu gostaria de saber como redimensiono imagens JPEG, pois tenho um BD MySQL que interage com o meu sistema desktop e o site da empresa, o que preciso fazer é um sistema que controle as noticias do site, ai o usuário poderá inserir, alterar, excluir as noticias atraves do sistema desktop, e as mudanças apareceram automaticamente no site, tudo isso já esta funcionando, porem quando coloca-se uma imagem com dimensões maiores que a página ele desconfigura todo o site, por isso necessito redimensionar a imagem. No BD só salvo o caminho da imagem, eu faço upload da imagem para o servidor atraves do Indy
Itepi
Curtidas 0
Respostas
Itepi
20/10/2008
Pessoal achei uns topicos aqui no forum sobre isso, e peguei uma função para isso:
porém esta dando o seguinte erro :
[color=red:f43eefe9b6][u:f43eefe9b6]scan line index out of range[/u:f43eefe9b6][/color:f43eefe9b6]
Alguem saberia como resolver?
procedure TFrmNoticia.ResizeBitmap(imgo, imgd: TBitmap; nw, nh: Integer); var xini, xfi, yini, yfi, saltx, salty: integer; x, y, px, py, tpix: integer; PixelColor: TColor; r, g, b: longint; P1, P2: PChar; pix: integer; begin // Set target size imgd.Width := nw; imgd.Height := nh; imgo.PixelFormat := pf32bit; imgd.PixelFormat := pf32bit; P1 := imgo.ScanLine[imgo.Height - 1]; P2 := imgd.ScanLine[imgd.Height - 1]; // Calcs width & height of every area of pixels of the source bitmap saltx := imgo.Width div nw; salty := imgo.Height div nh; yfi := 0; for y := 0 to nh - 1 do begin // Set the initial and final Y coordinate of a pixel area yini := yfi; yfi := yini + salty; if yfi >= imgo.Height then yfi := imgo.Height - 1; xfi := 0; for x := 0 to nw - 1 do begin // Set the inital and final X coordinate of a pixel area xini := xfi; xfi := xini + saltx; if xfi >= imgo.Width then xfi := imgo.Width - 1; // This loop calcs del average result color of a pixel area // of the imaginary grid r := 0; g := 0; b := 0; tpix := 0; for py := yini to yfi do begin for px := xini to xfi do begin Inc(tpix); pix := (imgo.Height - py - 1) * imgo.Width + px; PixelColor := (PColor(P1 + pix*4)^); r := r + PixelColor shr 16 and $ff; g := g + PixelColor shr 08 and $ff; b := b + PixelColor shr 00 and $ff; end; end; // Draws the result pixel //imgd.Canvas.Pixels[x, y] := rgb((r div tpix),(g div tpix),(b div tpix)); pix := (imgd.Height - y - 1) * imgd.Width + x; PColor(P2 + pix*4)^ := rgb((r div tpix),(g div tpix),(b div tpix)); end; end; end;
porém esta dando o seguinte erro :
[color=red:f43eefe9b6][u:f43eefe9b6]scan line index out of range[/u:f43eefe9b6][/color:f43eefe9b6]
Alguem saberia como resolver?
GOSTEI 0