Board index » delphi » D3 : BMP ---> JPEG

D3 : BMP ---> JPEG

On Mon, 27 Sep 1999 10:55:09 +0200, in borland.public.delphi.graphics

Quote
you wrote:
>How to Convert BMP ( stored in one field in table - Table1.BmpField ) to
>JPEG ( file - 'c:\jpegfile.jpg' ) ?

Put JPEG in your uses clause.

var
  BS: TBlobStream;
  JP: TJPEGImage;
begin
  BS := TBlobStream.Create(Table1.FieldByName('BmpField') as
TBlobField, bmRead);
  try
    JP := TJPEGImage.Create;
    try
      JP.LoadFromStream(BS);
      JP.SaveToFile('c:\jpegfile.jpg');
    finally
      JP.Free;
    end;
  finally
    BS.Free;
  end;
end;

Untested!

Nick Hodges
TeamB

 

Re:D3 : BMP ---> JPEG


tnx, but line

        JP.LoadFromStream(BS);

raise exception EJPEG : JPEG error #52

The same message in D3 and D4.

I don't now what this message means ( May be it expects JPEG  and not BMP -
    The same message accures by command   JP.LoadFromFile ('c:\onebmp.bmp')
; ).

Brane

Original :

Quote
>Put JPEG in your uses clause.

>var
>  BS: TBlobStream;
>  JP: TJPEGImage;
>begin
>  BS := TBlobStream.Create(Table1.FieldByName('BmpField') as
>TBlobField, bmRead);
>  try
>    JP := TJPEGImage.Create;
>    try
>      JP.LoadFromStream(BS);
>      JP.SaveToFile('c:\jpegfile.jpg');
>    finally
>      JP.Free;
>    end;
>  finally
>    BS.Free;
>  end;
>end;

>Untested!

>Nick Hodges
>TeamB

Re:D3 : BMP ---> JPEG


Try setting the position of the Stream back to 0 before you call
LoadFromStream.  LoadFromStream starts at the current postition and the Create
does not reset to the beginning.  Error #52 means an invalid JPEG image which
when streaming is usually because the stream position is not in the correct
place.  Without looking at the TJpegImage code I can't say for sure, but it
might not accept streaming a bitmap and automatically converting it.

Another alternative is to load the bitmap into a TBitmap (you can still use
streams there) and then just call the JPeg's Assign method passing the TBitmap.

Quote
Brane wrote:

> tnx, but line

>         JP.LoadFromStream(BS);

> raise exception EJPEG : JPEG error #52

> The same message in D3 and D4.

> I don't now what this message means ( May be it expects JPEG  and not BMP -
>     The same message accures by command   JP.LoadFromFile ('c:\onebmp.bmp')
> ; ).

> Brane

> Original :
> >Put JPEG in your uses clause.

> >var
> >  BS: TBlobStream;
> >  JP: TJPEGImage;
> >begin
> >  BS := TBlobStream.Create(Table1.FieldByName('BmpField') as
> >TBlobField, bmRead);
> >  try
> >    JP := TJPEGImage.Create;
> >    try
> >      JP.LoadFromStream(BS);
> >      JP.SaveToFile('c:\jpegfile.jpg');
> >    finally
> >      JP.Free;
> >    end;
> >  finally
> >    BS.Free;
> >  end;
> >end;

> >Untested!

> >Nick Hodges
> >TeamB

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
Mild mannered supermen are held in kryptonite, and the wise and foolish
{*word*269}s giggle with their bodies glowing bright.  Through the door a harvest
feast is lit by candlelight; it's the bottom of the staircase that spirals out
of sight.
  (new classic Genesis) Carpet Crawlers 1999
--

Re:D3 : BMP ---> JPEG


Jeff --

Thanks for the pickup.  I should have remembered that.

Nick Hodges
TeamB

Other Threads