Delphi 2005 and JPEG

Delphi 2005 and JPEG

Post by Mark Reich » Fri, 22 Dec 2006 06:41:35


I have a program that will need to regularly display JPEGs from a blob field
on a SQL server. Occasionally, it will have to load a JPG file and save it
to the server.

Is there a way to handle this with Delphi 2005 and beyond without resorting
to the now sourceless JPEG file?
 
 
 

Delphi 2005 and JPEG

Post by Anton » Fri, 22 Dec 2006 16:03:33

"Mark Reichert" < XXXX@XXXXX.COM > wrote in message
news:4589ad3a$ XXXX@XXXXX.COM ...

I don't know if it is what you're looking for, but I've been using this for
myself for years now. Your Blob fields can be unknown type and if you want a
datacontrol like TDBImage, replace it with TImage and in the OnAfterScoll of
the dataset you can use PhotoFieldToImage
etc.

Just copy whole unit & save.

Cheers


unit DBPhotos;

interface

uses DBTables,ExtDlgs,db,ExtCtrls, SysUtils, Dialogs;

function
OpenPhotoClick(OpenDialog:TOpenPictureDialog;Field:TBlobField;Image:TImage):Boolean;
procedure PhotoFieldToImage(Field:TBlobField;Image:TImage);
procedure PhotoFileToField(FileName:String;Field:TBlobField);
procedure PhotoImageToField(Image:TImage;Field:TBlobField);
procedure SaveImageToFile(Image:TImage;FileName:String);

implementation

uses JPeg,Forms,Controls,DBStuff,Graphics;

procedure SaveImageTofile(Image:TImage;FileName:String);
var J:TJPegImage;
begin;
if Uppercase(Copy(FileName,Length(FileName)-2,3))='JPG'
then begin;
J:=TJPegImage.Create;
J.Assign(Image.Picture.Bitmap);
J.SaveTofile(FileName);
J.Free;
end
else Image.Picture.SaveToFile(FileName);
end;

procedure PhotoFileToField(FileName:String;Field:TBlobField);
var Jpg : TJPEGImage;
Strm:TBlobStream;
Pic:TPicture;
begin
if FileName=''
then exit;
Pic:=TPicture.Create;
try
Screen.Cursor:=crHourGlass;
EditDB(Field.DataSet);
Field.Clear;
Pic.LoadFromFile(Filename);
except
on EInvalidGraphic do
begin;
Pic.Graphic := nil;
Pic.Free;
Screen.Cursor:=crDefault;
exit;
end
else Screen.Cursor:=crDefault;
end;
Strm:=TBlobStream(Field.DataSet.CreateBlobStream(Field,bmWrite));
{Stream.Create(Field,bmWrite);}
Jpg:=TJPegIMage.Create;
JPG.CompressionQuality:=98;
try
if Pic.Graphic is tJPegImage
then begin;
TJpegImage(Pic.Graphic).SaveToStream(Strm);
end
else begin;
Jpg.Assign(Pic.Bitmap);
JPG.CompressionQuality:=98;
JPG.SaveToStream(Strm);
end;
finally
Strm.Free;
JPG.Free;
{Pic.Free;}
end;
Screen.Cursor:=crDefault;
end;

procedure PhotoImageToField(Image:TImage;Field:TBlobField);
var Jpg : TJPEGImage;
Strm:TBlobStream;
begin
EditDB(Field.DataSet);
Field.Clear;
if Image.Picture=nil
then exit;
Screen.Cursor:=crHourGlass;
Strm:=TBlobStream(Field.DataSet.CreateBlobStream(Field,bmWrite));
{Stream.Create(Field,bmWrite);}
Jpg:=TJPegIMage.Create;
JPG.CompressionQuality:=98;
try
if Image.Picture.Graphic is tJPegImage
then begin;
TJpegImage(Image.Picture.Graphic).SaveToStream(Strm);
end
else begin;
Jpg.Assign(Image.Picture.Bitmap);
{JPG.CompressionQuality:=98;}
JPG.SaveToStream(Strm);
end;
finally
Strm.Free;
JPG.Free;
{Pic.Free;}
end;
Screen.Cursor:=crDefault;
end;

function
OpenPhotoClick(OpenDialog:TOpenPictureDialog;Field:TBlobField;Image:TImage):Boolean;
var Jpg : TJPEGImage;
Strm:TBlobStream;
begin
Result:=False;
if not OpenDialog.Execute
then exit;
try
Screen.Cursor:=crHourGlass;
EditDB(Field.DataSet);
Image.Picture.LoadFromFile(OpenDialog.Filename);
except
on EInvalidGraphic do
begin;
Image.Picture.Graphic := nil;
Screen.Cursor:=crDefault;
 
 
 

Delphi 2005 and JPEG

Post by Mark Reich » Fri, 22 Dec 2006 23:40:57


Thank you, that will be useful. It does however seem to use the now
sourceless JPEG.DCU (meaning JPEG.PAS is no longer provided on the Delphi
CDs).
 
 
 

Delphi 2005 and JPEG

Post by Team » Sat, 23 Dec 2006 03:46:25


If you want to avoid that you have to find some 3rd-party replacement
for TJpegImage.
However, with BDS 4.0 jpeg.pas *is* on the first CD, in the
info\extras\jpeg folder.



--
Peter Below (TeamB)
Don't be a vampire ( http://www.yqcomputer.com/ ),
use the newsgroup archives :
http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/
 
 
 

Delphi 2005 and JPEG

Post by Mark Reich » Sat, 23 Dec 2006 04:53:04


Do you or anybody else have any recommendations?


With BDS 3.0 for Delphi 2005 Enterprise, the only info directory I can find
(and it was on the third CD) has BDEMergeModule as its sole subdirectory. I
did a search on all three CD's for jpeg.pas.
 
 
 

Delphi 2005 and JPEG

Post by Team » Sun, 24 Dec 2006 01:53:17


The JEDI VCL may have something but I don't know for certain.
TJpegImage has always been good enough for my purposes, so I never
looked for replacements.


Mh, it may have been left off by accident then.



--
Peter Below (TeamB)
Don't be a vampire ( http://www.yqcomputer.com/ ),
use the newsgroup archives :
http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/
 
 
 

Delphi 2005 and JPEG

Post by Nils Haec » Sun, 24 Dec 2006 04:44:45

..and what does Jpeg.pas bring you? Its just a wrapper around .obj files,
which are sourceless as well.

If you want to use "true native jpg", look up Jacques Nomssi Nzali's pasjpeg
librarly.
http://www.yqcomputer.com/

Nils

"Mark Reichert" < XXXX@XXXXX.COM > schreef in bericht
 
 
 

Delphi 2005 and JPEG

Post by Eddie Lott » Sun, 24 Dec 2006 05:33:54


GDI+ is also very useful. You can get the Delphi unit from Progdigy.com

Cheers
Eddie
 
 
 

Delphi 2005 and JPEG

Post by Dennis Pas » Sun, 24 Dec 2006 07:11:51

Hey Mark;

Lets try this it way

http://www.yqcomputer.com/

this is a complete project that will compile and build in
Delphi 7, BDS2005 and BDS2006
 
 
 

Delphi 2005 and JPEG

Post by Mark Reich » Sun, 31 Dec 2006 01:09:32


This is probably too late a reply. I downloaded it and will definitely look
at it but haven't had the chance to yet.
 
 
 

Delphi 2005 and JPEG

Post by Dennis Pas » Sun, 31 Dec 2006 05:55:28

>This is probably too late a reply.

I am still hear on a daily basis so if you have any questions
just ask and I well get back to you shortly.
 
 
 

Delphi 2005 and JPEG

Post by Mark Reich » Fri, 19 Jan 2007 02:36:26


I've finally taken a look at the project in your ADOPictures.zip.

Is there some particular reason it pops up a console window?
 
 
 

Delphi 2005 and JPEG

Post by Dennis Pas » Sat, 20 Jan 2007 08:03:16

>Is there some particular reason it pops up a console window?

I just went back and ran Project2.exe and I do not see
a Console WIndow opening up any where.