Link to home
Start Free TrialLog in
Avatar of winexec
winexec

asked on

JPEG component

Hello.

I need to use jpeg but without existing jpeg unit in Delphi 7, the main reason being the size of the executable (I use only windows and messages units). If anyone knows where I can find a JPEG component which works in Delphi 7 please let me know.

Thanks.
Avatar of ThoseBug
ThoseBug

i have dbjpeg component..if you want i can send to your email.
Avatar of winexec

ASKER

Sure, if that component doesn't need Classes or other delphi units is perfect.

My email: <edited from AnnieMod for user privacy>

Big thx :)
try http://www.torry.net this site has loads of components for delphi and it list what it will work in
Avatar of winexec

ASKER

thx for the link, but what I need isn't there...

I increased the points to 300...
did you receive my component? it works?
Avatar of winexec

ASKER

@ThoseBug: thx for emailing me that component, but isn't what I need... That component is using the JPEG unit from delphi... I need a component which can replace the JPEG unit and doesn't use classes, graphix etc., only Windows unit.

@gangsterboss: I'll check the links, thx.
Avatar of winexec

ASKER

@gangsterboss: just a suggestion: from now on, please post only if you understand the question and you are sure that your comment could help, otherwise is a waste of time for both of us.

Again: I need to use jpeg, but without the existing JPEG unit from delphi, and must work on delphi 7. The JPEG unit I need must use only Windows unit. If anyone knows such a unit please help me. The points could be increased. Thx.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of winexec

ASKER

Hello Slick812, thx a lot for explaining :)

Yes, I know about KOL's JPEG unit. If you converted the JPEG and Graphics from KOL (to use'em w/o KOL) and you can send me those units could be perfect for me, even if there are only few k less...

My email is: <edited by AnnieMod for user privacy>

Thx again:)
SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of winexec

ASKER

@Workshop_Alex: Thx for comments :) I was born with D7, so I don't know much about those things...

Sure, I know that all components inherits from TComponent, so are using Classes, it was only a bad exprimation.

Yes, is quite interesting to make a small exe, dunno if it worth the effort but I like it.

Related to changing/moving methods etc. at KOL: I looked at that previously and I don't think I can manage all those things :( Please, if you know what to do and isn't needed too much effort on your side can you do it for me?

Thx.



 
Avatar of winexec

ASKER

Hm, I saw few email addresses in the past... Anyway, no problem if the rules are changing.
I do not have the time now to search for that old stuff now (I do not think that I saved some of it (any of it maybe), since it never worked correctly . . . but I do Have API apps the use the delphi Graphic and JPEG that are about, 180 KB. . .  

Sorry
mods, close this question or whatever, the following is added as a resource here at EE -

I'm not sure that this will apply to what you need, but it may help someone, , I have recently discovered the IPicture interface, I do not beleive I have seen it used in delphi before, I had alot and alot of problems with the Render method of IPicture, all of the code examples I found (in C) did not get the placement or size (or both) correct for the rendered images, they use a millimeter type of reference for one side and a pixel reference for the other side, resulting in a confusing (for me) code problem. But I got a workable size and placement for it. I have here a Unit called  IPic2Bmp.pas which uses the IPicture interface to load Images (bmp, jpg, gif, ico, wmf, emf) and maybe others into a full color 24 bit bitmap.
It only adds about 4 Kilobytes to your exe size, so it is useful to me for loading many types of Images from Files, like  .BMP  .GIF  .JPG  .EMF  .ICO  .WMF  , , , However it will not save any images to file, and you can not create any images with it.
  It has a single function

function GethBmp(FileName: String; out Size: TPoint; BkColor: Cardinal = 0): Integer;

the FileName is the name and Path of an Image File, the Size is a TPoint that will return the pixel dimentions in the x and y (width and height) for the new bitmap., The bkColor is the fill color used empty new bitmap, this is only important if you get a "Transparent" type of image, like a transparent .GIF .ICO .WMF or .EMF, that's right, it will automatically do the transpanency.
The Result is a Handle for a 24 bit DIB bitmap, the same width and height as the image of the file. If this function returns zero then it has failed.


 - - - - - - - - -  -  code for the IPic2Bmp.pas  file  - - - - - -  -- -


unit IPic2Bmp;

interface


uses Windows;

function GethBmp(FileName: String; out Size: TPoint; BkColor: Cardinal = 0): Integer;

implementation

const
  IID_IPicture: TGUID = (
    D1:$7BF80980;D2:$BF32;D3:$101A;D4:($8B,$BB,$00,$AA,$00,$30,$0C,$AB));

type
  ISequentialStream = interface(IUnknown)
    ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
    function Read(pv: Pointer; cb: LongInt; pcbRead: PLongInt): HResult;
      stdcall;
    function Write(pv: Pointer; cb: LongInt; pcbWritten: PLongInt): HResult;
      stdcall;
  end;
 
  IStream = interface(ISequentialStream)
    ['{0000000C-0000-0000-C000-000000000046}']

  end;

  IPicture = interface
    ['{7BF80980-BF32-101A-8BBB-00AA00300CAB}']
    function get_Handle(out handle: DWord): HResult;  stdcall;
    function get_hPal(out handle: DWord): HResult; stdcall;
    function get_Type(out typ: Smallint): HResult; stdcall;
    function get_Width(out width: Longint): HResult; stdcall;
    function get_Height(out height: Longint): HResult; stdcall;
    function Render(dc: HDC; x, y, cx, cy: Longint;
      xSrc: Longint; ySrc: Longint; cxSrc: Longint; cySrc: Longint;
      const rcWBounds: TRect): HResult; stdcall;
    function set_hPal(hpal: DWord): HResult; stdcall;
    function get_CurDC(out dcOut: HDC): HResult; stdcall;
    function SelectPicture(dcIn: HDC; pdcOut: PDWord;
      pBmpOut: PDWord): HResult; stdcall;
    function get_KeepOriginalFormat(out fkeep: BOOL): HResult; stdcall;
    function put_KeepOriginalFormat(fkeep: BOOL): HResult; stdcall;
    function PictureChanged: HResult; stdcall;
    function SaveAsFile(const stream: IStream; fSaveMemCopy: BOOL;
      out cbSize: Longint): HResult; stdcall;
    function get_Attributes(out dwAttr: Longint): HResult; stdcall;
  end;


function CreateStreamOnHGlobal(hglob: HGlobal; fDeleteOnRelease: BOOL;
  out stm: IStream): HResult; stdcall;  external 'ole32.dll';

function OleLoadPicture(stream: IStream; lSize: LongInt; fRunmode: BOOL;
  const iid: TGUID; out pic: IPicture): HResult; stdcall; external 'olepro32.dll';


function GethBmp(FileName: String; out Size: TPoint; BkColor: Cardinal = 0): Integer;
var
hFile, SizeF, hGMem, ReadSize, hABmp, DC1: Cardinal;
pMemJpg, pBits: Pointer;
StreamI: IStream;
PictureI: IPicture;
mmWidth, mmHeight, brush, oBr, offI: Integer;
bRect: TRect;
Pnt1: TPoint;
siType: SmallInt;
BmpInfo1: TBitmapInfo;

begin
Result := 0;
Size.x := 0;
Size.y := 0;
if Length(Filename) < 4 then Exit;
hFile := CreateFile(PChar(FileName), GENERIC_READ, FILE_SHARE_READ,
    nil, OPEN_EXISTING, 0, 0);
if hFile = INVALID_HANDLE_VALUE then
  begin
  //MessageBox(0, 'CreateFile  FAILED', pError, MB_ICONERROR);
  Exit;
  end;

SizeF := GetFileSize(hFile, nil);
if (SizeF = $FFFFFFFF) or (SizeF < 32) then
  begin
  CloseHandle(hFile);
  //MessageBox(0, 'GetFileSize  FAILED', pError, MB_ICONERROR);
  Exit;
  end;

hGMem := GlobalAlloc(GMEM_MOVEABLE, SizeF);
if hGMem = 0 then
  begin
  CloseHandle(hFile);
  //MessageBox(0, 'GlobalAlloc  FAILED', pError, MB_ICONERROR);
  Exit;
  end;

pMemJpg := GlobalLock(hGMem);
if pMemJpg = nil then
  begin
  CloseHandle(hFile);
  GlobalFree(hGMem);
  //MessageBox(0, 'GlobalLock  FAILED', pError, MB_ICONERROR);
  Exit;
  end;

if not ReadFile(hFile, pMemJpg^, SizeF, ReadSize, nil) or (SizeF <> ReadSize) then
  begin
  CloseHandle(hFile);
  GlobalUnlock(hGMem);
  GlobalFree(hGMem);
  //MessageBox(0, 'ReadFile  FAILED', pError, MB_ICONERROR);
  Exit;
  end;
CloseHandle(hFile);
GlobalUnlock(hGMem);
if CreateStreamOnHGlobal(hGMem, TRUE, StreamI) <> S_OK then
  begin
  GlobalFree(hGMem);
  //MessageBox(0, 'CreateStreamOnHGlobal  FAILED', pError, MB_ICONERROR);
  Exit;
  end;

if OleLoadPicture(StreamI, SizeF, FALSE, IID_IPicture, PictureI) <> S_OK then
  begin
  GlobalFree(hGMem);
  //MessageBox(0, 'OleLoadPicture  FAILED', pError, MB_ICONERROR);
  Exit;
  end;
GlobalFree(hGMem);

PictureI.get_Width(mmWidth);
PictureI.get_Height(mmHeight);
Pnt1.x := mmWidth;
Pnt1.y := mmHeight;
Dc1 := GetDC(0);
SetMapMode(DC1, MM_HIMETRIC);
LPTODP(DC1, Pnt1, 1);
ReleaseDC(0, Dc1);

if PictureI.get_Handle(hABmp) <> S_OK Then
  begin
 // MessageBox(0, 'PictureI.get_Handle  FAILED', pError, MB_ICONERROR);
  Exit;
  end;


ZeroMemory(@BmpInfo1, sizeOf(BmpInfo1));
with BmpInfo1.bmiHeader do
  begin
  biSize := sizeOf(BmpInfo1.bmiHeader);
  biWidth := Pnt1.x;
  biHeight := -Pnt1.y;
  biPlanes := 1;
  biBitCount := 24;
  biSizeImage := ((biWidth * biBitCount) + 31) and not 31;
  biSizeImage := Integer((biSizeImage shr 3)) * biHeight;
  end;

pBits := nil;
DC1 := CreateCompatibleDC(0);
Result := CreateDIBSection(DC1, BmpInfo1, DIB_RGB_COLORS, pBits, 0, 0);

if Result = 0 then
  begin
  DeleteDC(DC1);
  //MessageBox(0, 'ERROR - Can NOT Create a Bitmap from file = system resources low',
  //             E_Read, MB_ICONERROR);
  Exit;
  end;
SelectObject(DC1, Result);
  brush := CreateSolidBrush(BkColor);
  oBr := SelectObject(DC1, brush);
  PatBlt(DC1,0, 0, Pnt1.x, -Pnt1.y, PATCOPY);
  DeleteObject(SelectObject(DC1, oBr));


SetRect(bRect, 0,0,Pnt1.x, -Pnt1.y);

PictureI.get_Type(siType);

if siType <> 3 then
  offI := 0 else offI := 26;

if PictureI.Render(DC1,0, -(Pnt1.y+(offI div 26)) ,Pnt1.x,Pnt1.y,0,
                   offI, mmWidth, mmHeight, bRect) <> S_OK then
  begin
  DeleteObject(hABmp);
  DeleteObject(Result);
  Result := 0;
  DeleteDC(DC1);
  //MessageBox(0, 'PictureI.Render FAILED', pError, MB_ICONERROR);
  Exit;
  end;
Size.x := Pnt1.x;
Size.y := -Pnt1.y;
DeleteDC(DC1);
DeleteObject(hABmp);
end;

end.


 - - - - - - -  - - - - - - - - - - - - - - - - - - - -  - - - - - - - -  - - - -

here is some code to use this in an API program

program whatever;

uses
  Messages, Windows, IPic2Bmp, CommDlg;


function OpenDialog1(const FolderName: String; Owner: Integer): String;
var
  ofname : TOpenFilename;
  TempName: Array[0..2047] of Char;
begin
ZeroMemory(@TempName, SizeOf(TempName));
ZeroMemory(@ofname, SizeOf(ofname));
with ofname do
  begin
  lStructSize := sizeof(ofname);
  hwndowner := Owner;
  hInstance := SysInit.hInstance;
  nMaxFile := 2047;
  lpstrFile := @TempName;
  lpstrFilter := 'Image files, bmp jpg gif ico wmf emf'#0+
      '*.bmp;*.jpg;*.jpeg;*.gif;*.ico;*.wmf;*.emf'#0'BMP file *.bmp'#0+
      '*.bmp'#0'JPG file *.jpg'#0'*.jpg'#0#0;
  lpstrTitle := PChar('Open an  Image  File');
  nFilterIndex := 1;
  lpstrInitialDir:= PChar(FolderName);
  Flags := OFN_EXPLORER or OFN_LONGNAMES or OFN_PATHMUSTEXIST or
           OFN_FILEMUSTEXIST;
  end;

if GetOpenFileName(ofname) then
  Result := TempName
  else
  Result := '';
end;



procedure GetIPic;
var
hBmp1, fDC, DC1: Integer;
Size1: TPoint;
Filename: String;
begin
FileName := OpenDialog1('E:\', hForm1);
if Filename = '' then Exit;
hBmp1 := GethBmp(Filename, Size1, GetSysColor(COLOR_BTNFACE));
if hBmp1 = 0 then
  begin
  MessageBox(hForm1, 'ERROR - No Bitmap Handle, IPicture Failed',
             'No BMP Handle', MB_ICONERROR);
  Exit;
  end;

DC1 := CreateCompatibleDC(0);
SelectObject(DC1, hBmp1);
fDC := GetDC(hForm1);
BitBlt(fDC, 6, 82, Size1.x, Size1.y, DC1, 0, 0, SRCCOPY);
DeleteDC(DC1);
ReleaseDC(hForm1, fDC);
DeleteObJect(hBmp1);
end;