Author |
Topic  |
|
johnrboren

USA
12 Posts |
Posted - Mar 30 2012 : 23:30:36
|
I posted this once before, but need an updated solution.
If I load a JPEG image from disk or from a SQL Database table, I want to determine the actual storage size of the image.
The previous solution was this:
result:=Image1.IEBitmap.Height * Image1.IEBitmap.RowLen;
The only thought I have is to save the file to disk every time I load it and then read the file properties. That is extremely slow and inefficent. However, seems to me this can be calculated and exposed as a property.
Can anyone assist?
JOHN BOREN |
|
fab
   
1310 Posts |
Posted - Mar 31 2012 : 23:26:56
|
I imagine you have the jpeg stored in a "Blob" field, so you could directly load the content using streams, without save the file to disk. Also ImageEn doesn't need to load the full file in order to know the image size. Instead of use LoadFromFileJpeg just call ParamsFromFile (there are similar methods to work with streams). For example: Image1.IO.ParamsFromFile('myjpeg.jpg'); result := Image1.IO.Params.Height * Image1.IO.Params.Width * Image1.IO.Params.SamplesPerPixel;
The above code doesn't care about end of line bytes padding (0..3 bytes per row).
|
 |
|
johnrboren

USA
12 Posts |
Posted - Apr 01 2012 : 09:04:54
|
I'm using an ImageEnDBView object to do this already. So, I wrote the code as you suggested.
// //****************************************************************** // // GetPhotoSize - Pass the Image to get the photo size // function TFPhotoFuncs.GetPhotoSize(Image1: TImageEnDBView): integer; var MyDataset:TDataSet; MyField:TField; MyStream:TStream; begin result:=0; if Image1.DataSource=nil then Exit; MyDataSet:=Image1.DataSource.DataSet; MyField:=MyDataSet.FieldByName(Image1.DataField); if MyField<>nil then MyStream:=MyDataset.CreateBlobStream(MyField,bmRead) else Exit;
Image1.IO.ParamsFromStream(MyStream); result:=Image1.IO.Params.Height * Image1.IO.Params.Width * Image1.IO.Params.SamplesPerPixel; //******************************************************************
1. This still doesn't get the appropriate file length. The Image size on disk is 173,938 bytes. The calculated size using the above method or the previous IEBitmap method still is 3,154,176 bytes.
2. I have attached the photo. If you could let me know what changes I need to make to make this work would be great.
3. I really don't want to have to do this from the IO process. Reason is, if I crop the photo, as I can in our product, or make any other changes in the photo, I want to get the photo size AFTER I make those changes and BEFORE I save it back to the database or a file.
 170.26 KB
JOHN BOREN |
 |
|
johnrboren

USA
12 Posts |
Posted - Apr 01 2012 : 09:07:11
|
Here is a screen shot of the bytes in our app.
Why can't we just get a function like this:
MySize:=ImageDBEnView.PhotoSize;
 387.65 KB
JOHN BOREN |
 |
|
johnrboren

USA
12 Posts |
Posted - Apr 01 2012 : 09:13:26
|
Maybe onto something here. Gave this some further thought.
If I just use the Stream size, then its right. However, if I crop the photo or other changes, its not updating the photo size. Anyway of doing that from a stream size of the image?
//******************************************************************* // // GetPhotoSize - Pass the Image to get the photo size // function TFPhotoFuncs.GetPhotoSize(Image1: TImageEnDBView): integer; var MyDataset:TDataSet; MyField:TField; MyStream:TStream; begin result:=0; if Image1.DataSource=nil then Exit; MyDataSet:=Image1.DataSource.DataSet; MyField:=MyDataSet.FieldByName(Image1.DataField); if MyField<>nil then MyStream:=MyDataset.CreateBlobStream(MyField,bmRead) else Exit;
Result:=MyStream.Size;
JOHN BOREN |
 |
|
fab
   
1310 Posts |
Posted - Apr 03 2012 : 02:36:22
|
quote: 1. This still doesn't get the appropriate file length. The Image size on disk is 173,938 bytes. The calculated size using the above method or the previous IEBitmap method still is 3,154,176 bytes.
They are two different sizes. One is compressed size (the actual jpeg), and the other is the uncompressed size (the actual allocated memory). What size do you need?
You cannot get the jpeg size (compressed size) without save the image to disk or in a temporary stream. |
 |
|
|
Topic  |
|
|
|