I am drawing an image into the destination rectangle (‘getLocalBounds().toFloat()’ ). I specified destX, destY, destWidth and destHeight parameters but I keep getting an error about the arguments being less or many. This is the code which seems right to me but don’t understand why I get this error.
You almost had it, but you provide two rectangles, the getLocalBounds() which is the whole component and the Rect.
Try instead:
g.drawImageWithin (image, 0, 100, 144, 144);
There is an additional parameter you can experiment with: RectanglePlacement, which is used to determine if the aspect ratio is allowed to change or what to do if it doesn’t fit.
That is just one of a few options, an overload taking a juce::Rectangle<float> exists as well, see drawImage().
The reason i am not using the coordinates in the image is because i am trying to display an image strip based on the current frame i dont want to draw the entire image.
int frameIndex = 0; // The index of the frame you want to display
int frameWidth = 44;
int frameHeight = imageStrip.getHeight() / numFrames; // Height of each frame
int sourceX_ = 0; // X-coordinate of the top-left corner of the frame in the image strip
int sourceY_ = frameIndex * frameHeight; // Y-coordinate of the top-left corner of the frame in the image strip
int sourceWidth_ = frameWidth; // Width of the frame
int sourceHeight_ = frameHeight; // Height of the frame
Rectangle<int> frameBounds(0, currentFrame * frameHeight, imageStrip.getWidth(), frameHeight);
g.drawImage(imageStrip, sourceX_, sourceY_, getWidth(), getHeight(), 0, 0, sourceWidth_, sourceHeight_);
I think you are almost there, you just mixed up the order:
destination comes first, then the source coordinates of your film strip.
int frameIndex = 0; // The index of the frame you want to display
int frameWidth = 44;
int frameHeight = imageStrip.getHeight() / numFrames; // Height of each frame
int sourceX_ = 0; // X-coordinate of the top-left corner of the frame in the image strip
int sourceY_ = frameIndex * frameHeight; // Y-coordinate of the top-left corner of the frame in the image strip
int sourceWidth_ = frameWidth; // Width of the frame
int sourceHeight_ = frameHeight; // Height of the frame
g.drawImage (imageStrip, 0, 0, getWidth(), getHeight(), sourceX_, sourceY_, sourceWidth_, sourceHeight_);