Jump to content

unidbimage and jpeg format


albertovesx

Recommended Posts

My solution ...
 
Replaces the TUniDBIMage by TUniImage and use the code below:
 
Uses
 JPEG, ExtDlgs;

// To read the image
procedure TFrmCadCliente.LoadImageFromField(Image: TUniImage;
  ImageField: TBlobField);
var
  MemStrm: TMemoryStream;
  Jpg: TJPEGImage;
begin
  if ImageField.IsNull then
  begin
    Image.Picture.Assign(nil);
    Exit;
  end; // if
  Jpg := TJPEGImage.create;
  try
    MemStrm := TMemoryStream.create;
    try
      ImageField.SaveToStream(MemStrm);
      MemStrm.Seek(0, soFromBeginning);
      with Jpg do
      begin
        PixelFormat := jf24Bit;
        Scale := jsFullSize;
        Grayscale := False;
        Performance := jpBestQuality;
        ProgressiveDisplay := True;
        ProgressiveEncoding := True;
        LoadFromStream(MemStrm);
      end; // with
      Image.Picture.Assign(Jpg)
    finally
      MemStrm.free;
    end; // try
  finally
    Jpg.free;
  end; // try
end;

// DS = TDataSource
procedure TFrmCadCliente.DSDataChange(Sender: TObject; Field: TField);
begin
  inherited;
  if DS.DataSet.State in [dsBrowse] then
    LoadImageFromField(FOTO, DM.cdsCLIENTEFOTO);
end;

// Insert Image
procedure TFrmCadPrestador.btnFOTOClick(Sender: TObject);
begin
  inherited;
  IsImage := False;
  UniFileUpload1.Execute;
end;


// Upload Image
procedure TFrmCadPrestador.UniFileUpload1Completed(Sender: TObject;
AStream: TFileStream);
var
  DestName: string;
  DestFolder: string;
begin
  inherited;
  if IsImage then
  begin
    FOTO.Picture.LoadFromFile(AStream.FileName); // FOTO = TUniImage
    DM.cdsCLIENTEFOTO.LoadFromFile(AStream.FileName);
  end
  else
  begin
    DestFolder := SM.StartPath + 'UploadFolder\';
    DestName := DestFolder + ExtractFileName(UniFileUpload1.FileName);
    CopyFile(PChar(AStream.FileName), PChar(DestName), False);
    FOTO.Picture.LoadFromFile(DestFolder + UniFileUpload1.FileName);
    if DS.DataSet.State in [dsBrowse] then
    begin
      DS.DataSet.Edit;
      DM.cdsCLIENTEFOTO.LoadFromFile(DestFolder + UniFileUpload1.FileName);
    end;
  end;
end;

// Clear Image
procedure TFrmCadCliente.FOTODblClick(Sender: TObject);
begin
  inherited;
  if DS.State = dsinactive then
  begin
    ShowMessage('Abra um registro antes de alterar os dados!');
    Exit;
  end;
  if DM.cdsCLIENTEFOTO.IsNull then
  begin
    ShowMessage('Não há Foto nesse Cadastro!');
    Exit;
  end;
  if DS.State in [dsInsert, dsEdit] then
   // DS.DataSet.Edit; // [dsBrowse]
  DM.cdsCLIENTEFONTO.Clear;
  LOGO.Picture := nil;
end;

 

Be happy!

Link to comment
Share on other sites

Thank you. Your code is very useful.

 

But again all this code would be easier with support for jpeg in unidbimage

 

I agree!
 
There are trivial things that still need to deploy or improve the UniGUI.
 
Let's wait. Farshad been doing a great job!
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...