Use the compressed image resources to pay the same code in BREW

xiaoxiao2021-03-06  120

Everyone must take too much storage space for BMP. This problem is very worried. It is a simple game. The image resources have to take a few tens of hundred k, don't tell me to use PNG, using this thing is too big, too Don't think about PNG to BMP, I think of transplantation, look at the decompression code of PNG, I will take a headache.

In fact, everyone will turn over the help, it will find that 2.0 or more SDK supports the decompression object of a AEECLSID_UNZIPSTream, which is decompressed for the data compressed by Gzip.

OK, think of my solution: Use GZIP to compress BMP, then use aeeclsid_unzipstream to decompress.

My solution is about the following steps:

1, Gzip compresses BMP, must be Gzip, Winzip, WinRar can not

2, put the compressed BMP to the resource, the method is to change the compressed file to the suffix of .bmp, as the image resource added

3, use aeeclsid_unzipstream in the program to decompress, the code is as follows:

Void * unzipbmpex (mj * mj, char * res_file, uint16 id, int * w, int * h)

{

UINT32 NTMP, SIZE, L;

BYTE * BUF, * TMPBUF;

Void * pbmsource = null;

BYTE * PDATABYTES;

Void * BMP;

AeeImageInfo imageInfo;

Boolean Bval = True;

IF (null == (pbmsource = ishell_loadresdataex (mj-> a.m_pishell, res_file, id, restype_image, null, & size)) {Return null;} TmpBuf = (Byte *) malloc (size - *) (PBMSource)))); Memcpy (TMPBUF, (Byte *) PBMSource * (PBMSource)), size - * ((Byte *)))); IMEMASTREAM_SET (MJ-> Pmemstream, TmpBuf, Size - * (Byte *)), 0, False); L = (* (Byte *) PBMSource Size-4)) ((* ((Byte *) PBMSource Size-3)) < <8) ((Byte *) PBMSource Size-2)) << 16) ((* (Byte *) PBMSource Size-1)) << 24); ishell_freeresdata (MJ-> A .m_pIShell, pbmSource); buf = (byte *) MALLOC (l); IUNZIPASTREAM_SetStream (mj-> pIUnzipAStream, (IAStream *) mj-> pMemStream); nTmp = IUNZIPASTREAM_Read (mj-> pIUnzipAStream, (void *) buf, l ); If (NTMP> 0) {while (NTMP Piunzipastream, (void *) (BYTE *) (BYTE *) (BUF NTMP), L-NTMP) NTMP;} PDATABYTES = BYTE * (BUF); BMP = ConvertBMP (PDATabytes, & imageInfo, & bval); * w = imageinfo.cx; * h = imageinfo.cy; free (buf); return bmp;} else f ((ntmp == aee_stre AM_WOULDBLOCK || (NTMP == 0)) {free (buf); return null;} Return NULL;}

转载请注明原文地址:https://www.9cbs.com/read-126795.html

New Post(0)