[i18n] Improved TCustomResFlagImageList

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

[i18n] Improved TCustomResFlagImageList

Postby arhangelsoft » August 28th, 2012, 2:49 pm

Greetings, Kambiz!

i18n Library automatically include flag's images into output binary like bitmaps, but this format is very hudge.
i'm converted images into JPEG(economy 24 kb) and modify the i18nCtrls.pas see TCustomResFlagImageList class.
Below i've posted a modificated code:
Code: Select all
{ TCustomResFlagImageList }

function EnumBitmapsCallback(hModule: hModule; lpszType, lpszName: PChar;
  lParam: Integer): Integer; stdcall;
var
  IL: TCustomResFlagImageList absolute lParam;
  ISO_3166_2: string;
begin
  if (lpszType = 'JPEG') and (ULONG_PTR(lpszName) shr 16 <> 0) and
    (AnsiStrPos(lpszName, PChar(IL.GetResourcePrefix)) = lpszName) then
  begin
    SetString(ISO_3166_2, lpszName + Length(IL.GetResourcePrefix),
      StrLen(lpszName) - Cardinal(Length(IL.GetResourcePrefix)));
    IL.AddFlagFromResource(ISO_3166_2, lpszName, hModule);
  end;
  Result := 1;
end;

function TCustomResFlagImageList.AddFlagFromResource(const ISO_3166_2,
  ResName: string; hModule: hModule): Integer;
var
  JPEG: TJPEGImage;
  RS: TResourceStream;
  BMP: TBitmap;
begin
  if hModule = 0 then
    hModule := HInstance;

  JPEG := TJPEGImage.Create;
  BMP := TBitmap.Create;
  RS := TResourceStream.Create(HInstance, PChar(ResName), PChar('JPEG'));
  try
    JPEG.LoadFromStream(RS);
    BMP.Assign(JPEG);
    Result := AddFlag(UpperCase(ISO_3166_2), BMP.Handle);
  finally
    FreeAndNil(JPEG);
    FreeAndNil(BMP);
    FreeAndNil(RS);
  end;
end;

procedure TCustomResFlagImageList.PrepareFlags;
begin
  with GetFlagSize do
    SetSize(cx, cy);
  EnumResourceNames(HInstance, PChar('JPEG'), @EnumBitmapsCallback,
    Integer(Self));
end;

Mod/ images see in attachments.

Also I'm think that the flags images must be stored in language files as a streams, 1 language = 1 flag, not in EXE. But I'm don't understood how it's made.. What you think?
Attachments
i18n.zip
i18n flag's images as jpg, with mod. RC file.
(128.6 KiB) Downloaded 82 times
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk

Re: [i18n] Improved TCustomResFlagImageList

Postby Kambiz » August 29th, 2012, 1:24 pm

I used bitmap because JPEG doesn't support transparency.
The Swiss flag is square and the Nepal's flag is non-quadrilateral. Transparency is required for these two flags.
Using a few kilo bytes or even mega bytes more is nothing compare to the nowadays computers' Giga memories. But the quality is a matter indeed.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: [i18n] Improved TCustomResFlagImageList

Postby arhangelsoft » August 29th, 2012, 4:33 pm

What about PNG's using? Delphi 2009+ also supports it! This format is more useful than BMP and JPEG.
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk

Re: [i18n] Improved TCustomResFlagImageList

Postby Kambiz » August 29th, 2012, 6:14 pm

Regardless of the image format you use as the resource, Windows uses bitmaps for imagelists.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: Bing [Bot] and 40 guests

cron