Home > Back-end >  DELPHI SQL images stored in a binary stream read error
DELPHI SQL images stored in a binary stream read error

Time:11-17

Image data flow form ERROR save pictures, prompt JPEG ERROR # 53, has written the use JPEG, a great god, please help to see what the problem is,
Specific code is as follows:
Procedure Tfrm_cztz. Image1Click (Sender: TObject);//image1 controls click transfer into image
Var
Myjpeg: TJPEGImage;
Oldmybmp newmybmp: TBitmap;
, oldw, oldh neww, newh: integer;
OMemoStream: TMemoryStream;
The begin
Myjpeg:=TJPEGImage. Create;
Oldmybmp:=TBitmap. Create;
Newmybmp:=TBitmap. Create;
OMemoStream:=TMemoryStream. Create;
Neww:=200;
Newh:=200;
Try
With OpenDialog1 do
The begin
If the Execute then
The begin
CZTZ. Edit;//the data set editor status, or you can't give back data set assignment
Myjpeg. LoadFromFile (FileName);
//the following is according to the size of the new zoom
Oldmybmp. Assign (myjpeg);
Oldw:=oldmybmp. Width;
Oldh:=oldmybmp. Height;
Newmybmp. Width:=oldw * neww div oldw;
Newmybmp. Height:=oldh * newh div oldh;
SetStretchBltMode (newmybmp. Canvas. Handle, HalfTone);
StretchBlt (newmybmp. Canvas. Handle, 0, 0, neww, newh,
Oldmybmp. Canvas. Handle, 0, 0, oldw, oldh, SRCCOPY);
Myjpeg. Assign (newmybmp);
//quality according to the new image compression
Myjpeg.Com pressionQuality:=90;//to the quality of 90 is compressed
Myjpeg.Com press;
//show the processed images
Image1. Picture. Assign (myjpeg);
//is processed in the form of flow, avoid stored as files
Image1. Picture. Graphic. SaveToStream (oMemoStream);
OMemoStream. Position:=0;
TBlobField (CZTZ FieldbyName (' capture ')). LoadFromStream (oMemoStream);
CZTZ. Post;
Messagebox (getactivewindow (), 'image is saved! 'and' save ', mb_ok);
End
The else
exit;
end;
The finally
//release
Myjpeg. Free;
Oldmybmp. Free;
Newmybmp. Free;
OMemoStream. Free;
end;
end;



Procedure TFrm_cztz. ADOQueryAfterScroll (DataSet: TDataSet);//SQL display JPEG method
Var
OMemoStream: TMemoryStream;
PIC: tjpegimage;
The begin
OMemoStream:=TMemoryStream. Create;
PIC:=TJpegimage. Create;
Try
If not CZTZ. FieldByName (' screenshot). IsNull then
The begin
TBlobField (CZTZ FieldByName (' capture ')). SaveToStream (oMemoStream);
OMemoStream. Position:=0;
PIC. LoadFromStream (oMemoStream);
Image1. Picture. Graphic:=PIC;
End
The else
The begin
Image1. Picture:=nil;
end;
The finally
OMemoStream. Free;
PIC. Free;
end;
end;

CodePudding user response:

This is usually a flow in the process of handling errors,

CodePudding user response:

reference 1st floor lyhoo163 response:
error in the process and this is usually a flow

Positive solution,

CodePudding user response:

Through the way of binary data stream, read and write images, the images in the database

CodePudding user response:

My impression was that this has nothing to do with stream processing, as if is the problem with jpeg Image controls,
Processing flow is the same code, but I haven't had this change Image element to ImageEN control problem,
 
Buf:=TMemoryStream. Create;
With qryTech do
The begin
TBlobField (qryTech FieldByName (' Pic1). SaveToStream (Buf);
Buf. Position:=0;
Try
ImageEn1. IEBitmap. Read (Buf);
The finally
end;
Buf. The Clear;
TBlobField (qryTech FieldByName (' Pic2). SaveToStream (Buf);
Buf. Position:=0;
Try
ImageEn2. IEBitmap. Read (Buf);
The finally
end;

CodePudding user response:

Statement, mix with the jpeg, image also no problem

CodePudding user response:

Brother, you this sentence is wrong:
//is processed in the form of flow, avoid stored as files
Image1. Picture. Graphic. SaveToStream (oMemoStream);

Here will save the image data into BMP format, and you in the back of the database, while reading the code again with JPG to read directly, certainly there will be a Jpeg error 53

TGpegImage (PIC). LoadFromStream (oMemoStream);


Therefore, we need to modify here:
Myjpeg.Com press;
//show the processed images
Image1. Picture. Assign (myjpeg);
//is processed in the form of flow, avoid stored as files
//cancel this
//image1. Picture. Graphic. SaveToStream (oMemoStream);
//modify like this
Myjpeg. SaveToStream (oMemoStream);
OMemoStream. Position:=0;



CodePudding user response:

Myjpeg. Assign (newmybmp);
//quality according to the new image compression
Myjpeg.Com pressionQuality:=90;//to the quality of 90 is compressed
Myjpeg.Com press;
//show the processed images
Image1. Picture. Assign (myjpeg);

Debugging here see if myjpeg null values
  • Related