Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Scaled bitmap not displayed in BitmapButton

    SDK Help
    0
    2
    275
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 30/11/2016 at 06:11, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R18 
      Platform:      
      Language(s) :     C++  ;

      ---------
      Hello,

      my plugin loads an image from a file and displays it in a BitmapButtonCustomGui in the Attributes Manager.
      That works alright, but when I scale it after loading, it is no longer displayed, although the scaling code
      appears to be correct. I confirmed this by using ShowBitmap() after the scaling and it gives me the correct
      result (displays the image in the Picture Viewer with the new size).

      Scaling code:

        /\*\*
         \* Flags for #scale_uniform().
         \*/
        enum scale_uniform_direction
        {
          scale_uniform_w,
          scale_uniform_h
        };
      
        /\*\*
         \* Scale a bitmap uniformly to the specified size in the direction
         \* specified with #scale_uniform_direction. Returns a new bitmap, the
         \* input bitmap is NOT freed.
         \*/
        inline BaseBitmap\* scale_uniform(BaseBitmap const\* bmp, Int32 size,
            scale_uniform_direction direction)
        {
          if (!bmp) return nullptr;
          Int32 dw, dh;
          if (direction == scale_uniform_w) {
            dw = size;
            dh = (size / Float(bmp->GetBw())) \* bmp->GetBh();
          }
          else {
            dh = size;
            dw = (size / Float(bmp->GetBh())) \* bmp->GetBw();
          }
      
          AutoAlloc<BaseBitmap> out;
          if (!out) return nullptr;
          if (IMAGERESULT_OK != out->Init(dw, dh, out->GetBt())) return nullptr;
          bmp->ScaleIt(out, 256, true, true);
          return out.Release();
        }
      

      Loader code:

            Filename filename = fn.GetDirectory() + header.iconfile.c_str();
            this->icon->Init(filename);
      
            filename = fn.GetDirectory() + header.previewfile.c_str();  
            this->preview->Init(filename);  
            this->preview.Assign(utils::scale_uniform(  
                this->preview, this->icon->GetBw(), utils::scale_uniform_w));
      

      GetDParameter:

        Bool GetDParameter(GeListNode\* node, DescID const& did, GeData& data,
            DESCFLAGS_GET& flags) override
        {
          if (!node) return false;
          switch (did[0].id) {
            case MY_ICON:
            case MY_PREVIEW: {
              BitmapButtonStruct bbs(static_cast<BaseObject\*>(node), did, this->dirty);
              data = GeData(CUSTOMDATATYPE_BITMAPBUTTON, bbs);
              flags |= DESCFLAGS_GET_PARAM_GET;
              break;
            }
          }
          return ObjectData::GetDParameter(node, did, data, flags);
        }
      

      DescriptionGetBitmap message:

        Bool Message(GeListNode\* node, Int32 msg, void\* pdata) override
        {
          switch (msg) {
            case MSG_DESCRIPTION_GETBITMAP: {
              auto\* data = static_cast<DescriptionGetBitmap\*>(pdata);
              if (!data) return false;
              this->get_bitmap(\*data);
              return true;
            }
          }
          return ObjectData::Message(node, msg, pdata);
        }
      
        void get_bitmap(DescriptionGetBitmap& data)
        {
          switch (data.id[0].id) {
            case MY_ICON: {
              data.bmp = this->icon->GetClone();
              break;
            }
            case MY_PREVIEW: {
              data.bmp = this->preview->GetClone();
              break;
            }
          }
        }
      

      I have no idea what's happening 🤢 I hope anyone else does!

      Thanks in advance,

      Niklas

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 30/11/2016 at 11:28, xxxxxxxx wrote:

        Nevermind, I found the issue. I was accidentally using out->GetBt() instead of bmp->GetBt(). 😊

        1 Reply Last reply Reply Quote 0
        • First post
          Last post