norgepaul / TChromeTabs

Comprehensive Delphi implementation of Chrome's tab system
Other
215 stars 78 forks source link

Stop drawing ImageList as Icon, this results in poor quality image #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add a TImageList with one 32bits bitmap
2. Assign imageList to ChromeTabs component
3. Add a tab with imageindex = 0

What is the expected output? What do you see instead?
- expected: tab draw all colors of image from ImageList
- got: a poor quality icon converted from the bitmap

What version of the product are you using? On what operating system?
1.3 + Delphi 7

Please provide any additional information below.

Replace the code with:

uses
  pngImage; // add too your project -> http://pngdelphi.sourceforge.net/

function ImageListToTGPImage(ImageList: TCustomImageList; ImageIndex: Integer): 
TGPImage;
var
  bitmap: TBitmap;
  png: TPNGObject;
  stream: TStream;
begin
  stream := TMemoryStream.Create;
  try
    png := TPNGObject.Create;
    try
      bitmap := TBitmap.Create;
      try
        ImageList.GetBitmap(ImageIndex, bitmap);

        bitmap.Transparent := True;
        png.Assign(bitmap);
      finally
        bitmap.Free;
      end;

      png.SaveToStream(stream);
      stream.Position := 0;
    finally
      png.Free;
    end;
  except
    stream.Free;
    raise;
  end;

  Result := TGPBitmap.Create(TStreamAdapter.Create(stream, soOwned));
end;

Original issue reported on code.google.com by betoneto.tbo@gmail.com on 28 Aug 2013 at 12:33

GoogleCodeExporter commented 9 years ago
Thanks for the suggestion. I've incorporated your code with a few IFDEFs to 
allow users with Delphi 2008 and earlier to use an external pngImage library. 
Delphi 2009 and later will use your code by default.

Original comment by paul.tho...@easy-ip.net on 20 Jun 2014 at 7:49