Imagemin Unexpected in File C png Use force to Continue

RRS feed

  • Remove From My Forums

 locked

Adding JPG, PNG, GIF etc. images to resource RRS feed

  • Question

  • Hello all,
    I have finally released my TapTap Keyboard (www.taptapkeyb.wz.cz) so now I want to minimise file size by replacing BMP files with JPEG files (or better PNG files). But problem is that I cannot add JPEG file to resource as image but only as unknown data Sad Can somebody please help me with this?

All replies

  • Hi,

    AgainstTheWind wrote:

    I have finally released my TapTap Keyboard (www.taptapkeyb.wz.cz) so now I want to minimise file size by replacing BMP files with JPEG files (or better PNG files). But problem is that I cannot add JPEG file to resource as image but only as unknown data

    Yes that is correct. However you should be able to use an OS API such as SHLoadImageResource (see http://msdn2.microsoft.com/en-us/library/aa455004.aspx) if available on your platform to work around this.

    It will load the image, decompress it using a suitable image codec and return an HBITMAP to the uncompressed image for you.

    Hope this helps,

    Christopher Fairbairn

  • Thanks for help Wink but I don't understand it much :/ Where I should have this?

    Code Block

    IDG_MYIMAGE_GIF GIF DISCARDABLE "MyImage.gif".


    And how I should name "Resource type" on import window? I think I should name it GIF shouldn't I?

    BTW to load bitmap from resource I'm using this:

    Code Block

    g_hbmKeybd = LoadBitmap( g_hInstDll, MAKEINTRESOURCE(IDB_KEYBD2) ); // from "resource.rc/Bitmap/ IDB_KEYBD2"

    g_hdcKeybd = CreateCompatibleDC( NULL );

    g_hbmOld   = (HBITMAP)SelectObject( g_hdcKeybd, g_hbmKeybd );


    Can you please help me a little with this?

  • Hi,

    AgainstTheWind wrote:

    And how I should name "Resource type" on import window? I think I should name it GIF shouldn't I?

    This will depend upon the development tool you are using. If you are using Visual Studio 2005 when you select the file within the Import dialog a second dialog should appear asking for the "Custom Resource Type". You should be able to specify "GIF" within this dialog.

    You need to specify "GIF" as the resource type no matter what file format (*.png, *.jpg etc) your image is stored in.

    Alternativly you could open up the *.rc file for your project in a text editor and manually make the changes described in the documentation I referenced above (make sure you have a backup in case something goes wrong).

    You can draw your image using a code snippet such as the following to draw your image into a device context called 'hdc':

    Code Block

    BITMAP bm;

    HBITMAP image = SHLoadImageResource(g_hInst, IDR_GIF1);

    // Create a device context and select the

    // bitmap within it

    HDC hdcSrc = CreateCompatibleDC(hdc);

    SelectObject(hdcSrc, image);

    // Fill out a BITMAP structure (so we can

    // determine the size of the image)

    GetObject(image, sizeof (bm), &bm);

    // Draw the image onto 'hdc'

    BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY);

    You would need to add error handling and (more importantly) resource freeing code to this sample.

    Hope this helps,

    Christopher Fairbairn

    • Proposed as answer by Thursday, May 6, 2010 6:54 AM
  • Hello again,
    thanks for your help I have tryed to modify your code to operate with my code but obviously I'm doing it all wrong Sad


    Code Block

    g_hbmKeybd = LoadBitmap( g_hInstDll, MAKEINTRESOURCE(IDB_KEYBD1) );
    g_hdcKeybd = CreateCompatibleDC( NULL );
    g_hbmOld   = (HBITMAP)SelectObject( g_hdcKeybd, g_hbmKeybd );

    into this:


    Code Block

    HBITMAP image = SHLoadImageResource(g_hInstDll, IDR_GIF1);

    g_hbmKeybd = LoadBitmap( g_hInstDll, image );
    g_hdcKeybd = CreateCompatibleDC( NULL );
    g_hbmOld   = (HBITMAP)SelectObject( g_hdcKeybd, g_hbmKeybd );


    I think something is terribly wrong but I don't know what Sad Please can you waste some time with it?
    Thanks in advance Wink

  • Hi,

    I haven't had a chance to take a look at your test code in the other thread, but having a look at the snippets you posted I think you might have better success if you remove the following line from your second code sample:

    g_hbmKeybd = LoadBitmap( g_hInstDll, image );

    You should end up with something that looks like the following:

    g_hbmKeybd = SHLoadImageResource(g_hInstDll, IDR_GIF1);

    g_hdcKeybd = CreateCompatibleDC( NULL );
    g_hbmOld   = (HBITMAP)SelectObject( g_hdcKeybd, g_hbmKeybd );

    Notice that SHLoadImageResource already returns you an HBITMAP handle. So you don't need to use LoadBitmap.

    If you stepped through your original code you would probably find g_hbmKeybd would be 0, due to the call to LoadBitmap trying to find a resource with a resource ID matching what ever the value of the handle returned by SHLoadImageResource happened to be.

    SHLoadImageResource essentially does the same task as LoadBitmap, it simply allows you to use other image formats other than windows bmp.

    Hope this helps,

    Christopher Fairbairn

  • Hello again,
    thanks for the advice but I have tried it before and these errors had appeared:

    Error    5    error LNK2019: unresolved external symbol SHLoadImageResource referenced in function "public: virtual long __cdecl CInputMethod:Tongue Tiedelect(struct HWND__ *)" (?Select@CInputMethod@@UAAJPAUHWND__@@@Z) dvorak_implementation.obj

    Error    6    fatal error LNK1120: 1 unresolved externals        Windows Mobile 5.0 Pocket PC SDK

    Have you any idea what is wrong with the code please? Maybe for WM5 SDK there is another syntax I don't know

  • Hi,

    At the bottom of the MSDN documentation page for SHLoadImageResource (http://msdn2.microsoft.com/en-us/library/aa455004.aspx) you will notice it mentions requirements, and it lists the following:

    Library: Use Aygshell.lib.

    The most likely cause for the error you are mentioning is that your project settings do not include aygshell.lib and hence the linker does not know where to find an implementation of SHLoadImageResource. You should be able to go into your project settings (the linker tab) and add aygshell.lib as an additional dependency or input library.

    Hope this helps,

    Christopher Fairbairn

  • Hello again,
    yeah it's working now Wink Thanks very much for your help... I will put your name to the credits on TapTap Keyboard site (http://www.taptapkeyb.wz.cz) if you don't mind Wink

  • Hello again Wink
    sorry I'm anoying you again but I have serious bug with non-BMP images (in this case GIF images but also with PNG images) Sad Please download my keyboard sample http://www.taptapkeyb.wz.cz/files/Dvoraksip_test_GIF.zip compile it, run it (on emulator) and when you type around 13 lines in notepad then keyboard freezes and image redrawing is not working... you must restart device :/ E.g. keep tapping on button 1 (with number 1) and after you type around 13 lines in notepad you will see the freezing of the keyboard (one picture stay drawed but the second one cannot draw; typing is stil working - it is obvious it's something about SHLoadImageResource ).
    Please have you an idea what is wrong?

  • Hello,
    please can you suggest any advice how to fix this freezing?
    Thanks in advance for any advice

    Regards
    AgainstTheWind

parkerhouts1948.blogspot.com

Source: https://social.msdn.microsoft.com/Forums/en-US/5c095401-fa5a-4923-9665-75e47db6b216/adding-jpg-png-gif-etc-images-to-resource?forum=vssmartdevicesnative

0 Response to "Imagemin Unexpected in File C png Use force to Continue"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel