Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Scaling of image not working

    Cinema 4D SDK
    3
    4
    1.2k
    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.
    • G
      gogeta
      last edited by a_block

      Hi,
      I want to scale down my image by 50% of its original width. For example, if I have an image of resolution 1366x768 then the resultant image should be of 683x768 resolution. I am drawing the bitmap image in GeUserArea using DrawBitmap().
      For scaling, I have used bitmap->ScaleIt() and bitmap->ScaleBicubic() functions but no luck. The ScaleIt() function scales the image but not the object in it. The object looks exactly as it was in original image but what I want is the image should look like squeezed i.e. scaled down by 50% in width. The ScaleBicubic() is now working at all. Although my destination image is of small size than of source image, it is still not working. Please help me with this. Below is the source code that I am using:

       // create new bitmap
      AutoAlloc<BaseBitmap> scaledBitmap;
      if (scaledBitmap == nullptr)
        return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
      // get source bitmap dimensions
      const Int32 originalWidth = bitmap->GetBw();
      const Int32 originalHeight = bitmap->GetBh();
      // initialize new bitmap with half width of the size
      const Float scale = 0.5;
      const Float scaledWidth = originalWidth * scale;
      const Float scaledHeight = originalHeight;
      const IMAGERESULT result = scaledBitmap->Init((Int32)scaledWidth, (Int32)scaledHeight);
      if (result != IMAGERESULT::IMAGERESULT_OK)
      {
        return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
      }
      					
      // fill new bitmap with scaled content of the source bitmap
      const Int32 defaultBrightness = 256;
      //bitmap->ScaleIt(scaledBitmap, defaultBrightness, true, false);
      bitmap->ScaleBicubic(scaledBitmap, 0, 0, originalWidth, originalHeight, 0, 0, scaledWidth, scaledHeight);
      ShowBitmap(scaledBitmap);
      DrawBitmap(scaledBitmap, x, y, scaledWidth, imageHeight, 0, 0, scaledWidth, scaledHeight, 	BMP_NORMALSCALED);
      

      Thanks in advance!

      Edit a_block: Added code tags.

      1 Reply Last reply Reply Quote 0
      • WickedPW
        WickedP
        last edited by

        Hi gogeta,

        I'm not sure on ScaleBicubic(), but I noticed in your commented line:

        //bitmap->ScaleIt(scaledBitmap, defaultBrightness, true, false);

        That last 'false' flag, try changing that to true. If you're scaling in a non-proportional way that should be true (might fix your non 'squeeze' issue).

        WP.

        wickedp.com

        G 1 Reply Last reply Reply Quote 2
        • G
          gogeta @WickedP
          last edited by

          @wickedp Wow! I can't believe I missed this point. Thanks a lot WP ☺ .
          I changed the flag and it worked.
          Thanks Again 😇 !

          1 Reply Last reply Reply Quote 0
          • a_blockA
            a_block
            last edited by

            Hi,

            I'm glad this already got solved. I just wanted to mention, I have added code tags to the initial post.

            Cheers,
            Andreas

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