Fórum TImage mostrando campo blob #352833
01/02/2008
0
Tem uma tabela com um campo Blob que pode conter imagens bmp ou jpg.
Gravar a imagem no campo não tem problema... ta td ok.
O engôdo é pra mostrar a imagem no formulário de cadastro.
Utilizando o DBImage não serve pq mostra somente os bmp e fica em branco qdo é jpg.
Estou agora tentando substituir o DBImage pelo TImage.
No momento que estou gravando não tem problema jogar do TImage pra o campo blob, mas o caminho de volta tá difícil. Pesquisando aqui no forum mesmo peguei a rotina abaixo que utilizei no evento afteropen do dataset:
procedure TFormFuncionarios.Cds1AfterOpen(DataSet: TDataSet);
var
BlobStream : TStream;
JPEGImage : TJPEGImage;
begin
DM1.SdsPesq.Active:=true;
BitBtn2.Enabled:=true;
BitBtn5.Enabled:=true;
BitBtn1.Enabled:=false;
BitBtn7.Enabled:=false;
BitBtn6.Enabled:=false;
if Cds1Codigo.AsInteger>0 then
begin
BitBtn3.Enabled:=true;
BitBtn4.Enabled:=true;
end;
if cds1foto.BlobSize<>0 then
begin
BlobStream:=cds1.CreateBlobStream(cds1FOTO,bmRead);
JPEGImage:= TJPEGImage.Create;
try
JPEGImage.LoadFromStream(BlobStream);
image1.Picture.Assign(JPEGImage);
finally
BlobStream.Free;
JPEGImage.Free;
end;
end
else
begin
image1.Picture:=nil;
end;
end;
Mas está apresentando erro na linha:
JPEGImage.LoadFromStream(BlobStream);
Erro apresentado:
Project Comercial.exe raised exception class EJPEG with message ´JPEG error #53´.
Algum colega sabe como solucionar isso?
Ou tenha uma outra forma de mostrar campos blob em TImage?
Catunda
Curtir tópico
+ 0Posts
01/02/2008
Onjahyr
JPEG Error #53 Or Out Of Memory Error When Attempting To Insert A Large JPG Into A Container Field
Question
JPEG Error 53 Or Out Of Memory Error When Attempting To Insert A Large JPG Into A Container Field
Answer
APPLICABLE TO
FileMaker Pro 3.x, FileMaker Pro 4.x, FileMaker Pro 5, FileMaker Pro 5.5
ISSUE
When attempting to insert a very large JPG image into a container field or layout in FileMaker Pro for Windows, the error ´JPEG Error 53´ or an error ´ImageName could not be imported. Ran out of memory while translating the file.´ may occur. This is because the image required more memory to decompress than FileMaker Pro can allocate.
RESOLUTION
FileMaker Pro for Windows is only able to allocate approximately 16 megabytes of memory to decompress an inserted image. If an image is so large that it requires more than 16 megabytes of memory to decompress, one of the above errors may be returned and the image will not be inserted. The image file must be scaled to a smaller size, number of colors, or resolution, in order to import into FileMaker Pro for Windows.
[b:fe7a4417db]Veja estes fóruns também:[/b:fe7a4417db]
(inglês)
http://newsgroups.cryer.info/borland/public.delphi.graphics/200608/0608152563.html
(português)
http://forum.clubedelphi.net/viewtopic.php?t=73753&postdays=0&postorder=asc&highlight=jpg&start=15
Blz.
Gostei + 0
01/02/2008
Aroldo Zanela
A melhor alternativa, testada com FB 2.0 e o componente [url=http://codecentral.borland.com/Item/22742]EDBImage[/url] de Sebastian Mayora. Há muitos tópicos aqui no fórum sobre o uso do mesmo.
Gostei + 0
06/02/2008
Rkatze
function TFormCfg.GravaArqCfg(FileName: String): Boolean;
var
ArqCfg: TIniFile;
Stream : TMemoryStream;
begin
Result := False;
try
ArqCfg := TIniFile.Create(FileName);
// salva a imagem do componente image, usando graphic grava no formato que foi lida a imagem.
// para ler tem que especificar o tipo da imagem, quando lido de um arquivo ele
// identifica pela extenção, mas por stream tem que testar para saber o formato que foi gravado
// o formato padrao do componente é Bitmap, para Jpeg tem que declarar a classe em uses
Stream := TMemoryStream.Create;
image1.Picture.Graphic.SaveToStream(Stream);
Stream.Position:=0;
Stream.SaveToFile(fArqBin);
Stream.Destroy;
ArqCfg.Free;
Result := True;
finally
end;
end;
function TFormCfg.LeArqCfg(FileName: String): Boolean;
var
ArqCfg: TIniFile;
Stream : TMemoryStream;
JPeg : TJPegImage;
icon : Ticon;
Bmp : TBitmap;
begin
Result := false;
try
Image1.Picture.Assign(nil); // limpa a imagem
// testa para saber o formato da imagem
if FileExists(fArqBin) then
Begin
Try
Stream := TMemoryStream.Create;
Stream.Clear;
Stream.Position:=0; // posição inicial, necessario para mais que uma leitura
Stream.LoadFromFile(fArqBin);
if Stream.Size > 0 then
try
Jpeg:=TJPegImage.Create;
Stream.Position:=0;
Jpeg.LoadFromStream(Stream);
image1.Picture.Assign(Jpeg);
Jpeg.Free;
labelImage.Caption:= ´Imagem Jpeg´;
except
try
Icon:=TIcon.Create;
Stream.Position:=0;
Icon.LoadFromStream(Stream);
image1.Picture.Assign(Icon);
Icon.Free;
labelImage.Caption:= ´Imagem Icone´;
except
try
Bmp:=TBitmap.Create;
Stream.Position:=0;
Bmp.LoadFromStream(Stream);
image1.Picture.Assign(Bmp);
Bmp.Free;
labelImage.Caption:= ´Imagem Bitmap´;
except
labelImage.Caption:= ´Imagem não suportada´;
end
end
end
finally
Stream.Destroy;
end;
end;
finally
Result := true;
end;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)