Link to home
Start Free TrialLog in
Avatar of thousandjulys
thousandjulys

asked on

SMALL Jpeg unit, lib, or component

im looking for a SMALL jpeg unit, library or component that can take a bitmap handle (HBitmap) and save it as a jpeg file. needs to be SMALL and doesnt use any vcl units for a small project. thanks!
Avatar of shaneholmes
shaneholmes

Ok, first,

OTTOMH

Uses Graphics, Jpeg;


TempBitmap := TBitmap.Create;
TempBitmap.Handle := HBITMAP;
Canvas.Draw(0, 0, TempBitmap);
with TJPegImage.Create do
 begin
  Assign(tempBitMap);
  SaveToFile('Filename.jpg');
  Free;
 end;
TempBitmap.Free;

Shane
Or something like this:

{...}
MemBitmap        := TBitmap.Create;
MemBitmap.Handle := "HBITMAP";

Image1.Width  := MemBitmap.Width;
Image1.Height := MemBitmap.Height;
Image1.Canvas.Draw(0, 0, MemBitmap);

with TJPegImage.Create do
 begin
  Assign(Image1.Picture.Bitmap);
  SaveToFile('Filename.jpg');
  Free;
 end;


MemBitmap.Free;
{...}



Avatar of thousandjulys

ASKER

i dont want a procedure with delphi's jpeg component... that uses VCLs, i want a component that uses no vcls to produce a small project.
Good Luck!

Shane
hello thousandjulys, The Jpeg compression and decompression code is very complex and long, if you look for the JPEG unit code in delphi it is not there, because most of it in in pre-made obj files. . . and these jpeg code alone will add about 70-90  Kilobytes to your executable, these JPEG will depend on a system DIB (bitmap) so you will need code to handle a system DIB, and that is not so easy, I have done a minor version. . . You may as well use the Graphics Unit and the Jpeg unit of Delphi (adding 120 Kilobytes or more) to your executable, because I looked and I could NOT find anything even close to what you are asking for, some dicussion about this is at this EE question - -

https://www.experts-exchange.com/questions/20752685/JPEG-component.html

If you are interested in API delphi programming you might look at my site -

http://www.angelfire.com/hi5/delphizeus/index.html
i already have a dcu file thats about 70k that has a few obj files, but it messes up the image if its not in 16bit, how bout is there any way to convert a bitmap handle of a 32bit image to 16 bit?
I'm not to sure about what you are asking? ? You can NOT ever convert a bitmap from one color depth (Format, bit number) to another, what you will need to do is create another different bitmap of whatever color format you need, and then BitBlt the first bitmap on the second bitmap and then DeleteObject( ) on the first bitmap. Replace the first bitmap with a copy (in the required format). This is what happens in the delphi graphics unit when you change the pixel format of a TBitmap. I have some other code here at EE for a DIB creation, you can look at this question -

https://www.experts-exchange.com/questions/20752840/Screen-capture.html


I think there is enough there for you to create a DIB of any pixel bit format (16 bit), even if you do not need to save it to file, I may have some time tommorow to get you some code to do a 16 bit DIB creation and BitBlt the orginal hBitmap on it
?? for my own info, where did you find this  "dcu file thats about 70k" that does JPEG compression? ? Many of the JPEG stuff I have seen will take a 24 bit bitmap, not a 16 bit
LOMJpeg is the small jpeg lib (http://www.lommage.co.uk/), and what you explained on how to move one bitmap with a certain color depth to another, is pretty much converting it.
and yeah if you have a procedure that converts a handle to a bitmap thats 32bit and rewrites it on a 24bit (24 is fine too) that would be nice. would it be possible to do it without creating any files?
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
im trying to do that BitBlt but it keeps ending up just leaving the newly made 16bit bitmap all black. any tips on that procedure :-)
??? It work fine for me
It seems that you are not familar with API bitmap coding, you will need to be somewhat able to do API Bitmap, if you want to do this kind of thing, it ain't delphi bitmap

I am assuming that the   h32Bmp    is a valid system bitmap handle, although it does NOT matter what color depth it is , it can be 32, 24 bit or other


hNewBmp := Make16BitBmp(aBmp.Handle);

aDC1 := CreateCompatibleDC(0);
SelectObject(aDC1, hNewBmp);
bDC2 := CreateCompatibleDC(0);
SelectObject(bDC2,  h32Bmp);
BitBlt(aDC1, 1, 1, aBmp.width, aBmp.Height, bDC2, 0, 0, SRCCOPY);
DeleteDC(aDC1);
DeleteDC(bDC2);

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

I read the Read me file on the LOMJpeg thing, and I do NOT think that is a good Idea, you should only work with 24 bit bitmaps with a JPEG conversion, that is the native format for the JPeg file bitmap to use (At least for versions of JPEG that are not "NEW" and since this craps out on 32 bit, then it is NOT NEW)

so you might be better off if you change the line

biBitCount := 16;

to

biBitCount := 24;
OK, I copied and pasted the BitBlt thing
you will need to add the current width and height

BitBlt(aDC1, 0, 0, WhateverWidth, whateverHeight, bDC2, 0, 0, SRCCOPY);

if you draw a mental Zero on the width and height then you might try this - -

ZeroMemory(@DibSec.dsBm, SizeOf(DibSec.dsBm));
GetObject( h32Bmp, SizeOf(DibSec), @DibSec) ;
aDC1 := CreateCompatibleDC(0);
SelectObject(aDC1, hNewBmp);
bDC2 := CreateCompatibleDC(0);
SelectObject(bDC2,  h32Bmp);
BitBlt(aDC1, 0, 0, DibSec.dsBm.biWidth, DibSec.dsBm.biHeight, bDC2, 0, 0, SRCCOPY);
DeleteDC(aDC1);
DeleteDC(bDC2);
i know its not delphi bitmap buddy, u dont have to tell me what i think, especially when ur wrong. all i wanted was a sample, because all the sites ive googled are nonsense. thanks for the help.