Some JPEG files with the following formats aren't displaying in Delphi's TImage
control.
- issue resolved.. [TImage.Autosize] Checkbox in image control is not checked by default, and as a result the image wasn't resizing. I was working with this project.. https://community.embarcadero.com/blogs/entry/converting-to-grayscale-with-tbitmapscanline-property-39051
and comparing the speed to my existing grayscale code. The scanline process they use appears to be slightly faster than the scanline process that I currently have in place. It is a great starting point for someone working with images. I added the standard jpeg conversion code and scrollboxes when I ran into the issue and noticed the file size. I believe the question was valid, but I reworded it. If I find another related answer where the question is easier to find, I will pull this post. If not, I will leave it.
For example, from a Nikon digital camera.
Dimensions : Width 5184 x Height 3888
Vertical Resolution : 300 dpi
Color Representation : sRGB
Compressed bits/pixel : 2
Bit depth : 24
EXIF version : 0230
Attributes : N
From a Samsung cell phone camera:
Dimensions : Width 4128 x Height 2322
Horizontal & Vertical Resolution : 72 dpi
Color Representation : sRGB
Resolution unit : 2
Compressed bits/pixel : [blank]
Bit depth : 24
EXIF version : 0220
Attributes : A
A grayscale file from Adobe Photoshop:
Dimensions : Width 1800 x Height 3600
Horizontal and Vertical Resolution : 300 dpi
Color Representation : Uncalibrated
Compressed bits/pixel : [blank]
Bit depth : 8
EXIF version : [blank]
Attributes : A
A file with the exact format as the last one, but with much smaller dimensions, works.
Dimensions of one working file : Width 570 x Height 248
Files with 24-bit depth, smaller dimensions, and no resolution or compression settings, work correctly as well.
When I try to display the pictures using the code below, the picture on the failing files is always blank, and no errors are returned. It works perfectly with many other jpg
and bmp
files.
Is there a conversion that is required for sRGB formatted files? Is there a size limit on what the control can display on screen? If so, is there a way to display larger files?
procedure TForm1.btnBrowseClick(Sender: TObject);
var
bmp: TBitmap;
c2g: TColor2Grayscale;
ba: TBitmapAccess;
sw: TStopwatch;
jpg : TJPEGImage; // jpeg does not show 32-bit support in Delphi, only 24 and 8.
path, name, ext : string;
alreadyGray : boolean;
begin
bmp := TBitmap.Create;
jpg := TJPEGImage.Create;
OpenPicturedialog1.InitialDir := FindImageFolder(true);
if OpenPictureDialog1.Execute() then
try
name := OpenPictureDialog1.FileName;
path := ExtractFilePath(name);
ext := Lowercase ( ExtractFileExt(name) );
alreadyGray := false;
try
if ( ext = '.jpg' ) or ( ext = '.jpeg' ) then
begin
jpg.LoadFromFile(name);
bmp.Assign(jpg);
alreadyGray := jpg.Grayscale;
end
else
bmp.LoadFromFile( name );
except
on err: Exception do
begin
ShowMessage(err.Message);
Exit;
end;
end;
if bmp.PixelFormat = pfDevice then
bmp.PixelFormat := pf32bit;
Image1.Picture.Assign(bmp);
if alreadyGray then
begin
Image2.Picture.Assign(bmp);
Exit;
end;
finally
jpg.Free;
bmp.Free;
end;
end;