GARANTIR DESCONTO

Fórum Como identificar se é BMP ou JPG no BD? #321849

22/05/2006

0

Olá amigos...

Como faço para saber se na minha tabela de alunos o meu campo im_foto e bmp ou jpg ? Estou usando sqlserver.

Desde de já obg pela atenção de todos aki no forum


Alexespina

Alexespina

Responder

Posts

19/06/2013

Simplim Soluções

A função abaixo retorno um TBitmap, para usá-la chame assim:

getImagemCampo ((Query.FieldByName(IMAGEM_LOGO)) as tBlobfield,
Query.FieldByName(IMAGEM_LOGO).AsString);

De qualquer forma ela irá lhe retornar a imagem em Bitmap, o qual você pode usar no picture do TImage.



GetImagemCampo(cds.field

class function TConfiguracaoController.getImagemCampo(
pfb_Campo: TBlobField; Tipo: String): TBitmap;
var
ls_Stream: TStream;
jpeg: TJPEGImage;
lb_Bitmap: TBitmap;
ls_Auxi : String;
begin

try
try

lb_Bitmap := TBitmap.Create;
jpeg := TJPEGImage.Create;

// Carregamos a foto para o Stream
ls_Stream := pfb_Campo.DataSet.CreateBlobStream(pfb_Campo, bmRead);

// Verifica o tamanho da foto
if (ls_Stream.Size > 0) then
begin
ls_Auxi := Copy(Tipo, 1, 4);
if ls_Auxi = BMÞ“ then
begin
// se imagem for bitmap
lb_Bitmap.LoadFromStream(ls_Stream);
end;
if ls_Auxi = ÿØÿà then
begin
// Se imagem for jpeg
jpeg.LoadFromStream(ls_Stream);
lb_Bitmap.Assign(jpeg);
end;
Result := lb_Bitmap;
end;

except
raise;
end;
finally
FreeAndNil(jpeg);
FreeAndNil(ls_Stream);
end;

end;


Abcs
Anderson
Responder

Gostei + 0

19/06/2013

Simplim Soluções

Corrigida ....

A função abaixo retorno um TBitmap, para usá-la chame assim:

getImagemCampo ((Query.FieldByName(IMAGEM_LOGO)) as tBlobfield,
Query.FieldByName(IMAGEM_LOGO).AsString);

De qualquer forma ela irá lhe retornar a imagem em Bitmap, o qual você pode usar no picture do TImage.



GetImagemCampo(cds.field

class function TConfiguracaoController.getImagemCampo(
pfb_Campo: TBlobField; Tipo: String): TBitmap;
var
ls_Stream: TStream;
jpeg: TJPEGImage;
lb_Bitmap: TBitmap;
ls_Auxi : String;
begin

try
try

lb_Bitmap := TBitmap.Create;
jpeg := TJPEGImage.Create;

// Carregamos a foto para o Stream
ls_Stream := pfb_Campo.DataSet.CreateBlobStream(pfb_Campo, bmRead);

// Verifica o tamanho da foto
if (ls_Stream.Size > 0) then
begin
ls_Auxi := Copy(Tipo, 1, 2);
if ls_Auxi = BM then
begin
// se imagem for bitmap
lb_Bitmap.LoadFromStream(ls_Stream);
end;
ls_Auxi := Copy(Tipo, 1, 4);
if ls_Auxi = ÿØÿà then
begin
// Se imagem for jpeg
jpeg.LoadFromStream(ls_Stream);
lb_Bitmap.Assign(jpeg);
end;
Result := lb_Bitmap;
end;

except
raise;
end;
finally
FreeAndNil(jpeg);
FreeAndNil(ls_Stream);
end;

end;


Abcs
Anderson
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar