Scaling of image not working



  • 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.



  • 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 Wow! I can't believe I missed this point. Thanks a lot WP ☺ .
    I changed the flag and it worked.
    Thanks Again 😇 !


  • Global Moderator

    Hi,

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

    Cheers,
    Andreas