- Код: Выделить всё
var
aJpg:TJPEGImage;
InBMP: TBitmap;
begin
aJpg :=TJPEGImage.Create;
InBmp := TBitmap.Create;
aJpg.LoadFromFile(SysToUTF8('c:\test.jpg');
aJpg.CompressionQuality:=100;
InBmp.PixelFormat:=pf24bit;
InBmp.Assign(aJpg);
SavePictureToDB(InBmp,TBlobField(SQLQueryPictBase.FieldByName('picture')));
Сама процедура
- Код: Выделить всё
procedure SavePictureToDB(p:TBitmap;blob_field_stream:TBlobField);
var str,strb:TMemoryStream;
h:longint;
hb:array [1..4] of byte;
i:integer;
const
head1=#21#28#51#0#2#0#0#0#17#0#14#0#20#0#37#0;
head2='яяяяТочечный рисунок'#0'Paint.Picture';
head3=#0#1#5#0#0#2#0#0#0#7#0#0#0;
head4='PBrush'#0#0#0#0#0#0#0#0#0;
tail1=#0#0#0#0#0#0#0#0;
tail2=#0#0#1#5#0#0#0#0#0#0#0#173#5#254;
begin
str:=TMemoryStream.Create;
strb:=TMemoryStream.Create;
p.SaveToStream(strb);
str.Write(head1,16);
str.Write(head2,34);
str.Write(head3,13);
str.Write(head4,15);
h:=strb.Size+26;
for i:=1 to 4 do begin
hb[i]:=h mod 256;
h:=h div 256;
end;
str.Write(hb,4);
strb.Seek(0,soFromBeginning);
str.CopyFrom(strb,strb.Size);
str.Write(tail1,8);
str.Write(tail1,8);
str.Write(tail1,8);
str.Write(tail2,14);
strb.Seek(0,soFromBeginning);
blob_field_stream.LoadFromStream(str);
strb.Free;
str.Free;
end;