Opa,

Vale ressaltar que disponibilizei o source das Units scDBPictures e 
scDBPicturesConst.

O demo está no link 
(http://www.4shared.com/file/67344222/71f82185/Zeos_and_Picture.html?dirPwdVerified=4f84753f).
________________________________
[]'s, Silvio Clécio
Contatos/Blog
Skype: silvioprog
E-mail, Yahoo! Messenger: [EMAIL PROTECTED]
Gmail, Google Talk: [EMAIL PROTECTED]
Hotmail, MSN: [EMAIL PROTECTED]
BlogSpot: http://silvioclecio.blogspot.com/
"Vamos ajudar o Grupo e o Yahoo! Apague o conteúdo irrelevante!"



________________________________
De: Silvio Clécio <[EMAIL PROTECTED]>
Para: delphi-br@yahoogrupos.com.br
Enviadas: Segunda-feira, 10 de Novembro de 2008 15:20:05
Assunto: Res: [delphi-br] Ref. Campo BLOB


Olá pessoal,

Omar, eu tenho algo que acho que serve com algums alterações:

//////////// ///////// ///////// ///////// ////
// ------------ --------- --------- ------- //
//      .----{SC™ Softwares}-- --.        //
// /silvioprog@ yahoo.com. br/         //
//     `----------- --------- --´          //
// ------------ --------- --------- --------/ /
// Qualquer colaboração será bem-vinda!  //
// Nome: Silvio Clécio                   //
// Banco: Bradesco                       //
// Agência: 3045-7                       //
// Conta-corrente: 55597-5               //
// ------------ --------- --------- --------/ /
// Any collaboration will be welcome!    //
// Name: Silvio Clécio                   //
// Bank: Bradesco                        //
// Agency: 3045-7                        //
// Account: 55597-5                      //
// ------------ --------- --------- --------/ /
//////////// ///////// ///////// ///////// ////
//              __________               //
//            .'---------- `.             //
//            | .--------. |             //
//            | |  FREE  | |             //
//            | |SOFTWARE| |             //
//            | `--------' |             //
//            `----.--.--- -'             //
//           ______|__|__ ____            //
//          /  %%%%%%%%%%%%  \           //
//         /  %%%%%%%%%%%% %%  \          //
//         ^^^^^^^^^^^^ ^^^^^^^^          //
//////////// ///////// ///////// ///////// ////
unit scDBPicturesConst;

interface

const
// Compression
PNGCompressionLevel = 9; // use 1..9

// Descriptions
scPictureDescriptio n: array [1..6] of string = (
'Bitmap',
'Ícone',
'Metafile',
'CompuServe GIF Image',
'JPEG Image File',
'Portable Network Graphic'
);

// Filters
scPictureFileFilter : array [1..6] of string = (
'Bitmaps (*.bmp)|*.bmp' ,
'Ícones (*.ico)|*.ico' ,
'Metafiles (*.wmf)|*.wmf' ,
'CompuServe GIF Image (*.gif)|*.gif' ,
'JPEG Image File (*.jpg; *.jpeg)|*.jpg; *.jpeg',
'Portable Network Graphics (*.png)|*.png'
);

// Extensions
scPictureFileExt: array [1..6] of string = (
'.bmp',
'.ico',
'.wmf',
'.gif',
'.jpg',
'.png'
);

scInvalidPicture = 'Formato de arquivo não suportado ' +
'ou corrompido.' ;
scInvalidFieldBlob = 'O campo "%s" não é um campo BLOB válido.';

implementation

end.
____________ _________ _________ __

//////////// ///////// ///////// ///////// ////
// ------------ --------- --------- ------- //
//      .----{SC™ Softwares}-- --.        //
// /silvioprog@ yahoo.com. br/         //
//     `----------- --------- --´          //
// ------------ --------- --------- --------/ /
// Qualquer colaboração será bem-vinda!  //
// Nome: Silvio Clécio                   //
// Banco: Bradesco                       //
// Agência: 3045-7                       //
// Conta-corrente: 55597-5               //
// ------------ --------- --------- --------/ /
// Any collaboration will be welcome!    //
// Name: Silvio Clécio                   //
// Bank: Bradesco                        //
// Agency: 3045-7                        //
// Account: 55597-5                      //
// ------------ --------- --------- --------/ /
//////////// ///////// ///////// ///////// ////
//              __________               //
//            .'---------- `.             //
//            | .--------. |             //
//            | |  FREE  | |             //
//            | |SOFTWARE| |             //
//            | `--------' |             //
//            `----.--.--- -'             //
//           ______|__|__ ____            //
//          /  %%%%%%%%%%%%  \           //
//         /  %%%%%%%%%%%% %%  \          //
//         ^^^^^^^^^^^^ ^^^^^^^^          //
//////////// ///////// ///////// ///////// ////
unit scDBPictures;

interface

uses
SysUtils,
Dialogs,
Graphics,
DB, 
JvGIF,
jpeg,
PNGImage,
scDBPicturesConst;

function scDBPictureToBlob( BlobField: TBlobField;
Picture: TPicture): Boolean;
function scDBBlobToPicture( BlobField: TBlobField;
Picture: TPicture; out Description, FileFilter, FileExt: string;
out FileExtensionIndex: Integer): Boolean;
function scDBPictureIsValidT oDB(FileName: string): Boolean;

implementation

var
GIF: TJvGIFImage;
JPG: TJPEGImage;
PNG: TPNGObject;

procedure MsgErr(Msg: string);
begin
MessageDlg(Msg, mtError, [mbOK], 0);
end;

function scDBPictureToBlob( BlobField: TBlobField;
Picture: TPicture): Boolean;
procedure BlobFieldAssign;
begin
with BlobField do
begin
BlobField.DataSet. Edit;
Clear;
Assign(Picture. Graphic);
Result := True;
end;
end;
begin
// Set picture to blob

Result := False;

if (Picture = nil) or (BlobField = nil) then
Exit;

if not (BlobField.IsBlob) then
begin
MsgErr(Format( scInvalidFieldBl ob, [BlobField.FieldNam e]));
Exit;
end;

// Empty picture
with Picture.Graphic do
if (Empty) or (Width = 0) or (Height = 0) then
begin
MsgErr(scInvalidPic ture);
Exit;
end;

// Get picture
with Picture do
begin
// BMP to Blob
if (Graphic is TBitmap) then
BlobFieldAssign
else
// Icon to Blob
if (Graphic is TIcon) then
BlobFieldAssign
else
// Metafile to Blob
if (Graphic is TMetafile) then
BlobFieldAssign
else
// GIF to Blob
if (Graphic is TJvGIFImage) then
BlobFieldAssign
else
// JPEG to Blob
if (Graphic is TJPEGImage) then
BlobFieldAssign
else
// PNG to Blob
if (Graphic is TPNGObject) then
BlobFieldAssign
else
MsgErr(scInvalidPic ture);
end;
end;

function scDBBlobToPicture( BlobField: TBlobField;
Picture: TPicture; out Description, FileFilter, FileExt: string;
out FileExtensionIndex: Integer): Boolean;
begin
// Get picture of blob

Result := False;

if (Picture = nil) or (BlobField = nil) then
Exit;
if (BlobField.IsNull) then
Exit;

if not (BlobField.IsBlob) then
begin
MsgErr(Format( scInvalidFieldBl ob,
[BlobField.FieldNam e]));
Exit;
end;

Picture.Assign( nil); 
try
Picture.Bitmap. Assign(BlobField );
Description := scPictureDescriptio n[1];
FileFilter := scPictureFileFilter [1];
FileExt := scPictureFileExt[ 1];
FileExtensionIndex := 0;
Result := True;
except 
try
Picture.Icon. Assign(BlobField );
Description := scPictureDescriptio n[2];
FileFilter := scPictureFileFilter [2];
FileExt := scPictureFileExt[ 2];
FileExtensionIndex := 1;
Result := True;
except
try
Picture.Metafile. Assign(BlobField );
Description := scPictureDescriptio n[3];
FileFilter := scPictureFileFilter [3];
FileExt := scPictureFileExt[ 3];
FileExtensionIndex := 2;
Result := True;
except
try
GIF.Assign(BlobFiel d);
Picture.Assign( GIF);
Description := scPictureDescriptio n[4];
FileFilter := scPictureFileFilter [4];
FileExt := scPictureFileExt[ 4];
FileExtensionIndex := 3;
Result := True;
except
try
JPG.Assign(BlobFiel d);
Picture.Assign( JPG);
Description := scPictureDescriptio n[5];
FileFilter := scPictureFileFilter [5];
FileExt := scPictureFileExt[ 5];
FileExtensionIndex := 4;
Result := True;
except
try
PNG.Assign(BlobFiel d);
Picture.Assign( PNG);
Description := scPictureDescriptio n[6];
FileFilter := scPictureFileFilter [6];
FileExt := scPictureFileExt[ 6];
FileExtensionIndex := 5;
Result := True;
except
Picture.Assign( nil);
Description := '';
FileFilter := '';
Result := False;
MsgErr(scInvalidPic ture);
end;
end;
end;
end;
end;
end;
end;

function scDBPictureIsValidT oDB(FileName: string): Boolean;
var
I: Integer;
S: string;
begin
// Picture is valid to DB?

S := ExtractFileExt( FileName) ;
Result := False;
if (S = '.jpeg') or (S = '.jpe') then
begin
Result := True;
Exit; 
end;

for I := Low(scPictureFileEx t) to High(scPictureFileE xt) do
if S = scPictureFileExt[ I] then
begin
Result := True;
Break;
end;
end;

initialization
GIF := TJvGIFImage. Create;
JPG := TJPEGImage.Create;
PNG := TPNGObject.Create;
PNG.CompressionLeve l := PNGCompressionLevel ;

finalization
FreeAndNil(GIF) ;
FreeAndNil(JPG) ;
FreeAndNil(PNG) ;

end.

É só copiar/colar num "txt" e mudar a extenção para "pas".
____________ _________ _________ __
[]'s, Silvio Clécio
Contatos/Blog
Skype: silvioprog
E-mail, Yahoo! Messenger: [EMAIL PROTECTED] com.br
Gmail, Google Talk: [EMAIL PROTECTED] com
Hotmail, MSN: silvio_prog@ hotmail.com
BlogSpot: http://silvioclecio .blogspot. com/
"Vamos ajudar o Grupo e o Yahoo! Apague o conteúdo irrelevante! "

____________ _________ _________ __
De: Omar Marques <webomarmatrix@ yahoo.com. br>
Para: [EMAIL PROTECTED] os.com.br
Enviadas: Segunda-feira, 10 de Novembro de 2008 13:11:49
Assunto: [delphi-br] Ref. Campo BLOB

Salve Delphianos,

Alguém sabe como posso saber se tem um bitmap atribuído a um campo do tipo BLob.
Tenho um DBImage e queria, se tiver um bitmap válido no campo, ele exibí-lo. 
Caso 
contrário não.

Abraços.

Att.
Omar M. Haddad

Omar M. Haddad
Analista de Sistemas    


      Novos endereços, o Yahoo! que você conhece. Crie um email novo com a sua 
cara @ymail.com ou @rocketmail.com.
http://br.new.mail.yahoo.com/addresses

[As partes desta mensagem que não continham texto foram removidas]

Responder a