2
I was able to store images in my bank, the problem now is just to treat so that the images only enter the bank to a certain size, assuming: 800kb. How to proceed?
Follows the code:
Botão Gravar:
procedure TfrmFoto.SpeedButton1Click(Sender: TObject);
var
Jpeg : TJpegImage;
begin
if OPPicture.execute then
Image1.Picture.LoadFromFile(OPPicture.FileName);
if OPPicture.FileName <> '' then
begin
Jpeg := TJpegImage.Create;
Jpeg.LoadFromFile(OPPicture.FileName);
dmconn.zqFoto.Close;
dmconn.zqFoto.SQL.Clear;
dmconn.zqFoto.SQL.Add('INSERT INTO fotos(nome, fotoAnt) VALUES (:pnome, :pfotoant)');
dmconn.zqFoto.ParamByName('pnome').AsString := edtNome.Text;
dmconn.zqFoto.ParamByName('pfotoant').Assign(Jpeg);
dmconn.zqFoto.ExecSQL;
Jpeg.Free;
end;
end;
And here’s the other button:
Botão Ler:
procedure TfrmFoto.SpeedButton2Click(Sender: TObject);
var
sqltexto : string;
Jpeg : TJpegImage;
Stream : TStream;
begin
dmconn.zqFoto.Close;
dmconn.zqFoto.SQL.Clear;
dmconn.zqFoto.SQL.Add('SELECT nome, fotoAnt FROM fotos WHERE nome = :pnome');
dmconn.zqFoto.ParamByName('pnome').AsString := edtNomeLer.Text;
dmconn.zqFoto.Open;
Stream := dmconn.zqFoto.CreateBlobStream(dmconn.zqFoto.Fields[1],BMREAD);
try
Jpeg := TJpegImage.Create;
Jpeg.LoadFromStream(Stream);
Image2.Picture.Assign(Jpeg);
except
// Jpg.Free;
end;
Idea: It would not be easier to upload the image to some site directory and store in the database only the path of this directory combined with the file name?
– Marcelo Aymone
nor scroll friend, it would have to be in the same bank, and it is not site, it is a system for desktop, hence I need to show the stored image, however it can not be big, it would have to be up to 800kb in size, all I want is to just treat this.
– Ramon Ruan