Delphi implementation 24-bit True color icon

Source: Internet
Author: User

Introduction

Delphi is currently widely used visual development tools, it itself with a picture, icon editor--image Editor, but to Delphi7 so far, can not be true Color icon editor, it is a pity. Through the research of the icon file, the author realizes the 24-bit true color icon.

Format of icon file

First, analyze a specific icon. In the CS1.6, there is an icon Game.ico (), if the Winhex can be used for 16-edit software to open the icon file, we can see the following data:

00 00 01 00 04 00 10 10 00 00 00 00 00 00-68 05

00 00 46 00 00 00 10 10 00 00 00 00 00 00-68 03

The 08 A8 for all of the same

To be A8 0C at the same-

11 00 00 28 00 00 00 10 00 00 00 20 00

00 00 01 00 08 00 00 00 00 00 40 01 00 00-47 46

6C 6D, 6E 67 00 01 00 00 00 00 00 00 00 00

Let's say a few words about the specific meaning of these data. An icon file (*. ICO), which can actually contain more than one icon. Typically, each icon is converted to an icon image for a particular display device. The icon file consists of a file header and data, the ICO file begins with a record-type structure called Tagicondir, described in Delphi (the values in parentheses are specific data for the CS icon):

tagIconDir = packed record
idReserved:WORD;// 保留域,目前始终为 0(开始的数据$00 00)
idType:WORD; //定义为资源类型,图标值为 $0001、光标是$0002($0001)
idCount:WORD; //idCount 表示的是这个文件里包含了几个图标($0004)
idEntries:array[0..0] of tagIconDirEntry; //不包括本数组,以上一共6个字节
end;

The identries in this record is the array structure, the size of which is not always 1, and it needs to determine the true size of the array based on the number of icons (idcount). Its type is tagicondirentry record, defined as follows:

tagIconDirEntry = packed record
bWidth:BYTE;// 图标图片的显示宽度,以像素为单位,最大值为255 ($10=16D)
bHeight:BYTE;// 图标图片的显示高度,以像素为单位,最大值为255 ($10=16D)
bColorCount:BYTE;// 图标图片的颜色数($00)
bReserved:BYTE;// 保留域总是 0 ($00)
wPlanes:WORD;// 图标图片的位面数 ($00 00)
wBitCount:WORD;// 图标图片的颜色深度($00 00)
dwBytesInRes:DWORD;// 图标图片占用的数据量($00000568)
dwImageOffset:DWORD; // 图标图片的开始位置 ($00000046)
end;.// 这个结构是16个字节

The above Idcount represents the number of icons contained in the icon file, and each icon must have a tagicondirentry structure to represent the specific information of the icon. Based on the dwbytesinres and dwimageoffset of the structure, we can determine the position of the picture (icon). The data at that location is a record called agiconimage, which is defined as this:

tagIconImage = packed record
icHeader:TBitmapInfoHeader; //BMP文件的信息头
icColors:array[0..0]of TRGBQuad;
icXOR:array[0..0]of BYTE;
icAND:array[0..0]of BYTE;
end;

From this definition we can see that this content is a standard bitmap format, only two more items, Icxor and Icand, ordinary bitmap information is not the 2 members. As you know, when the icon is displayed, it is to use the Mask method to display 2 pairs of bitmaps in the same position to produce any contour, first use the XOR bitmap to pull out the area to be displayed, and then in the area of the pull out to show the need to display graphics. For this reason, the bitmap information header (Tbitmapinfoheader) in the bitmap format of the icon is shared by 2 bitmaps. The biggest difference between it and ordinary bitmap header information is the Tbitmapinfoheader.biheight member, which is obviously the sum of 2 pairs of bitmap heights. In this case, we need to know a bit about the format of the bitmap (BMP) file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.