Scaled bitmap not displayed in BitmapButton



  • 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



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

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


Log in to reply