Como Salvar Imagem Jpg no Firebird?

Delphi

11/05/2009

Olá, já pesquisei aqui no fórum e encontrei várias rotinas para gravação de imagem jpg no banco firebird, até conseguir gravar normalmente, mas como o sistema irá gravar muitas imagens e irá funcionar pela web tb, precisava que além de gravar no formato jpg e convertesse bmp para jpg, tb redimensionasse a imagem para um tamanho menor, para não pesar o carregamento via web. Achei essa rotina aqui no fórum que faz isso, mas não tou conseguindo implementar juntamente com a gravação no banco, Alguém poderia me dar um ajudinha para resolver isso:

procedure ResizeBitmap32(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;


Vandeir

Vandeir

Curtidas 0
POSTAR