hmsills
asked on
Loading JPeg Images into Oracle 8 Blob Field
I am loading a jpeg file into an Oracle8 blob field using a TJpegImage and Tmemorystream object. Here is the code:
procedure TFrGraphic.Button1Click(Se nder: TObject);
var
jp : TJpegImage;
st : TMemoryStream;
name, path : string;
begin
//exit;
path := txtfilepath.text;
name := txtfilename.text;
st := TMemoryStream.Create;
try
jp := TJpegImage.Create;
try
if true then
begin
jp.LoadFromFile(path+name) ;
jp.SaveToStream(st);
st.Seek(0,soFromBeginning) ;
{qmax.open;
pict_no := qMaxNum.AsInteger + 1;
qmax.close;
dmglobal.database1.StartTr ansaction;
dbtImages_.Insert; }
qryGraphicGRAPHIC.LoadFrom Stream(st) ;
{dbtImages_Pict_No.AsInteg er := pict_no;
dbtImages_Pict_File.AsStri ng := cpn; }
if reloading = true then
begin
reloading := false;
getimage := strtoint(txtdimagenum.text );
end;
qryGraphic.Post;
// dmglobal.database1.commit;
btnreload.Enabled := true;
end;
finally
jp.Free;
end;
finally
st.Free;
end;
txtfilepath.text := '';
txtfilename.text := '';
pnlLoad.visible := False;
end;
This appears to work fine. I am then displaying the image via a TImage object (with the stretch property set to true) using the following code:
procedure TFrGraphic.ShowPicture;
var
jp : TJpegImage;
st : TMemoryStream;
begin
st := TMemoryStream.Create;
try
jp := TJpegImage.Create;
try
FrGraphic.qryGraphicGRAPHI C.SaveToSt ream(st);
st.Seek(0,soFromBeginning) ;
jp.LoadFromStream(st);
if (jp.Width = 0) or (jp.height = 0) then
begin
FrGraphic.Image1.Picture.G raphic := nil;
Application.Processmessage s;
end
else
// FrGraphic.Image1.Visible := False;
begin
Application.Processmessage s;
FrGraphic.Image1.Picture.G raphic := jp;
DisplayPicture;
btnreload.Enabled := true;
end;
// PictArea.Caption := '';
finally
jp.Free;
end;
finally
st.Free;
end;
end;
This also appears to work except occasionally. In 2 out of 10 files when they are displayed, the first 20 bytes or so seam to be fine but then the
image appears to shift to the left and partially wrap around the right side.
Am I missing something? If I take the .jpg file and make a small adjustment to it (change the size of the image smaller or larger) and then reload the graphic into the database, it appears to be fine. These images are scanned black and white drawings.
Any advise would be appreciated.
procedure TFrGraphic.Button1Click(Se
var
jp : TJpegImage;
st : TMemoryStream;
name, path : string;
begin
//exit;
path := txtfilepath.text;
name := txtfilename.text;
st := TMemoryStream.Create;
try
jp := TJpegImage.Create;
try
if true then
begin
jp.LoadFromFile(path+name)
jp.SaveToStream(st);
st.Seek(0,soFromBeginning)
{qmax.open;
pict_no := qMaxNum.AsInteger + 1;
qmax.close;
dmglobal.database1.StartTr
dbtImages_.Insert; }
qryGraphicGRAPHIC.LoadFrom
{dbtImages_Pict_No.AsInteg
dbtImages_Pict_File.AsStri
if reloading = true then
begin
reloading := false;
getimage := strtoint(txtdimagenum.text
end;
qryGraphic.Post;
// dmglobal.database1.commit;
btnreload.Enabled := true;
end;
finally
jp.Free;
end;
finally
st.Free;
end;
txtfilepath.text := '';
txtfilename.text := '';
pnlLoad.visible := False;
end;
This appears to work fine. I am then displaying the image via a TImage object (with the stretch property set to true) using the following code:
procedure TFrGraphic.ShowPicture;
var
jp : TJpegImage;
st : TMemoryStream;
begin
st := TMemoryStream.Create;
try
jp := TJpegImage.Create;
try
FrGraphic.qryGraphicGRAPHI
st.Seek(0,soFromBeginning)
jp.LoadFromStream(st);
if (jp.Width = 0) or (jp.height = 0) then
begin
FrGraphic.Image1.Picture.G
Application.Processmessage
end
else
// FrGraphic.Image1.Visible := False;
begin
Application.Processmessage
FrGraphic.Image1.Picture.G
DisplayPicture;
btnreload.Enabled := true;
end;
// PictArea.Caption := '';
finally
jp.Free;
end;
finally
st.Free;
end;
end;
This also appears to work except occasionally. In 2 out of 10 files when they are displayed, the first 20 bytes or so seam to be fine but then the
image appears to shift to the left and partially wrap around the right side.
Am I missing something? If I take the .jpg file and make a small adjustment to it (change the size of the image smaller or larger) and then reload the graphic into the database, it appears to be fine. These images are scanned black and white drawings.
Any advise would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this
st := TMemoryStream.Create;
try
jp := TJpegImage.Create;
try
FrGraphic.qryGraphicGRAPHI
jp.LoadFromStream(st);
if (jp.Width = 0) or (jp.height = 0) then
begin
//FrGraphic.Image1.Picture
Application.Processmessage
end
else
// FrGraphic.Image1.Visible := False;
begin
Application.Processmessage
FrGraphic.Image1.Picture.G
DisplayPicture;
btnreload.Enabled := true;
end;
// PictArea.Caption := '';
finally
jp.Free; //Remenber the assignment above ?
end;
finally
st.Free;
end;
end;
Good luck.
T++, Radler.