Jump to content

Recommended Posts

Posted

Hi

 

Jpeg images are one of the most used for database application. However vcl and unigui dont have native suport for this format (I dont know why). Is is posible tha unidbimage could handle jpg images?

 

Best regards

Posted
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!

Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...