Q: Load bitmaps and icons from the programs's resources 
Answer:
This FAQ assumes that you have already bound your bitmaps or icons to your executable. If you need help adding bitmaps or icons to a project, see the FAQ on adding icons, cursors, and bitmaps to a BCB project. Bitmaps 
TBitmap contains two functions called LoadFromResourceID and LoadFromResourceName that allow you to load bitmaps from the program's resources. Use LoadFromResourceID when the ID of your bitmap resource is an integer (the RC file example used numeric ID's). Use LoadFromResourceName when the bitmap's ID is a string. If you used the Image Editor to create a .RES file, you will need LoadFromResourceName because the Image Editor saves the resources using string IDs. Here are some code examples.   // Loading a bitmap that uses numeric IDs.
  Graphics::TBitmap *bmp = new Graphics::TBitmap;
  bmp->LoadFromResourceID((int)HInstance,IDB_SPLASH);  // Loading a bitmap that uses string IDs, like the
  // ones that the Image Editor creates.
  Graphics::TBitmap *bmp = new Graphics::TBitmap;
  bmp->LoadFromResourceName((int)HInstance,"Bitmap1");  // Loading a bitmap into a TImage control
  // using numeric IDs.
  Image1->Picture->Bitmap->LoadFromResourceID((int)HInstance,IDB_SPLASH);Note: You can also use API functions to load the bitmaps. Use the API LoadBitmap function and assign the result to the Handle property of TBitmap. Icons TIcon is the VCL class for working with icons. Unlike TBitmap, TIcon does not contain member functions to help you load the icon. You must use the API functions LoadIcon or LoadImage to load the icon into a TIcon object. LoadIcon is simpler to use, but it can only load 32 x 32 icons. If you use LoadIcon to load an icon of any other size, the API will enlarge or shrink the icon image to 32 x 32. LoadImage allows you to load icons of any size, but it takes more arguments. Here are some icon examples.   // Load a 32 x 32 icon that uses an integer ID
  TIcon *icon = new Graphics::TIcon;
  icon->Handle=LoadIcon(HInstance,MAKEINTRESOURCE(ID_FOLDER_ICON));  // Load a 32 x 32 icon that uses a string ID
  TIcon *icon = new Graphics::TIcon;
  icon->Handle=LoadIcon(HInstance,"IconFolder");  // load a system icon
  TIcon *icon = new Graphics::TIcon;
  icon->Handle=LoadIcon(HInstance,IDI_EXCLAMATION);  // Load a 16 x 16 icon that uses an integer ID
  TIcon *icon = new Graphics::TIcon;
  icon->Handle=LoadImage(HInstance,
                         MAKEINTRESOURCE(ID_SMALL_FOLDER),
                         IMAGE_ICON,
                         16,16,
                         LR_LOADREALSIZE);  // Load a 16 x 16 icon that uses a string ID
  TIcon *icon = new Graphics::TIcon;
  icon->Handle=LoadImage(HInstance,
                         "SmallFolder"),
                         IMAGE_ICON,
                         16,16,
                         LR_LOADREALSIZE);  //Load an icon directly into a TImage control
  Image1->Picture->Icon->Handle = LoadIcon(HInstance,IDI_EXCLAMATION); 
--------------------------------------------------------------------------------Copyright © 1997-2000 by Harold Howe.
All rights reserved.  

解决方案 »

  1.   

    Q: Load bitmaps and icons from the programs's resources 
    Answer:
    This FAQ assumes that you have already bound your bitmaps or icons to your executable. If you need help adding bitmaps or icons to a project, see the FAQ on adding icons, cursors, and bitmaps to a BCB project. Bitmaps 
    TBitmap contains two functions called LoadFromResourceID and LoadFromResourceName that allow you to load bitmaps from the program's resources. Use LoadFromResourceID when the ID of your bitmap resource is an integer (the RC file example used numeric ID's). Use LoadFromResourceName when the bitmap's ID is a string. If you used the Image Editor to create a .RES file, you will need LoadFromResourceName because the Image Editor saves the resources using string IDs. Here are some code examples.   // Loading a bitmap that uses numeric IDs.
      Graphics::TBitmap *bmp = new Graphics::TBitmap;
      bmp->LoadFromResourceID((int)HInstance,IDB_SPLASH);  // Loading a bitmap that uses string IDs, like the
      // ones that the Image Editor creates.
      Graphics::TBitmap *bmp = new Graphics::TBitmap;
      bmp->LoadFromResourceName((int)HInstance,"Bitmap1");  // Loading a bitmap into a TImage control
      // using numeric IDs.
      Image1->Picture->Bitmap->LoadFromResourceID((int)HInstance,IDB_SPLASH);Note: You can also use API functions to load the bitmaps. Use the API LoadBitmap function and assign the result to the Handle property of TBitmap. Icons TIcon is the VCL class for working with icons. Unlike TBitmap, TIcon does not contain member functions to help you load the icon. You must use the API functions LoadIcon or LoadImage to load the icon into a TIcon object. LoadIcon is simpler to use, but it can only load 32 x 32 icons. If you use LoadIcon to load an icon of any other size, the API will enlarge or shrink the icon image to 32 x 32. LoadImage allows you to load icons of any size, but it takes more arguments. Here are some icon examples.   // Load a 32 x 32 icon that uses an integer ID
      TIcon *icon = new Graphics::TIcon;
      icon->Handle=LoadIcon(HInstance,MAKEINTRESOURCE(ID_FOLDER_ICON));  // Load a 32 x 32 icon that uses a string ID
      TIcon *icon = new Graphics::TIcon;
      icon->Handle=LoadIcon(HInstance,"IconFolder");  // load a system icon
      TIcon *icon = new Graphics::TIcon;
      icon->Handle=LoadIcon(HInstance,IDI_EXCLAMATION);  // Load a 16 x 16 icon that uses an integer ID
      TIcon *icon = new Graphics::TIcon;
      icon->Handle=LoadImage(HInstance,
                             MAKEINTRESOURCE(ID_SMALL_FOLDER),
                             IMAGE_ICON,
                             16,16,
                             LR_LOADREALSIZE);  // Load a 16 x 16 icon that uses a string ID
      TIcon *icon = new Graphics::TIcon;
      icon->Handle=LoadImage(HInstance,
                             "SmallFolder"),
                             IMAGE_ICON,
                             16,16,
                             LR_LOADREALSIZE);  //Load an icon directly into a TImage control
      Image1->Picture->Icon->Handle = LoadIcon(HInstance,IDI_EXCLAMATION);  
      

  2.   

    最好新建一个资源文件(可以用Delphi自带的Image Editor)
    USERES("catres.res");//再应用的开始//下面是我的一段代码,用来从资源文件的BMP图中取其中的一部分显示
    Graphics::TBitmap *Bitmap;
    Bitmap = new Graphics::TBitmap;
    TRect MyRect, MyOther;
    MyRect = Rect(0,0,50,50); //将来显示的位置区域
    MyOther = Rect(100,100,150,150); //从BMP图上抠下的区域
    Bitmap->LoadFromResourceName((int)HInstance, "CATBMP");//CATBMP是资源文件中定义的名字
    Image1->Canvas->CopyRect(MyRect, Bitmap->Canvas, MyOther);
    delete Bitmap;
    //我原来使用系统自带的资源文件,但是老出问题
    所以新建了一个资源文件就没错了
    代码是C++Builder的,应该和Delphi差不多,可以看懂
      

  3.   

    最好新建一个资源文件(可以用Delphi自带的Image Editor)
    USERES("catres.res");//再应用的开始//下面是我的一段代码,用来从资源文件的BMP图中取其中的一部分显示
    Graphics::TBitmap *Bitmap;
    Bitmap = new Graphics::TBitmap;
    TRect MyRect, MyOther;
    MyRect = Rect(0,0,50,50); //将来显示的位置区域
    MyOther = Rect(100,100,150,150); //从BMP图上抠下的区域
    Bitmap->LoadFromResourceName((int)HInstance, "CATBMP");//CATBMP是资源文件中定义的名字
    Image1->Canvas->CopyRect(MyRect, Bitmap->Canvas, MyOther);
    delete Bitmap;
    //我原来使用系统自带的资源文件,但是老出问题
    所以新建了一个资源文件就没错了
    代码是C++Builder的,应该和Delphi差不多,可以看懂
      

  4.   

    他问的是如何知道资源的ID,而不是资源的Name
    其实资源的ID就是创建资源时的顺序,好像是从0开始的,我不记得了
    你试试就知道了,楼上的朋友已把用法说得很清楚了
      

  5.   

    imgedit好像只支持256的bmp,我的是24位的,算了,不管它了,LoadFromFile,以后有空再研究,谢谢各位了,给分