Jump to content

Stretching selection horizontally to fit canvas


Recommended Posts

Hello!

 

May be a very simple, rather trivial question, but i can't seem to find the answer.

I'm trying to stretch a selection horizontally, but i don't know how.

 

Say i have a filled circle, with an alpha layer surrounding it.

I'd like to stretch that circle into a rectangle with the same filling, so that its edges are clamped to the canvas edges. And so that the stretched selection is evenly distributed from left to right edge.

 

Is this possible, or do i need a plugin?

 

Thanks in advance

Link to comment
Share on other sites

I'm not 100% sure I understand, but have you tried using the Rectangle Selection Tool :RectangleSelectTool: , over the circle till it fills the rectangle shape of the Tool, then Ctrl I to invert and then hit delete on your computer.

 

Or you may want to try this Grid Warp Plugin by @Pyrochild.

 

Plugin information can be found here as well.

 

Hope this helps answer yoyur question :)

Edited by david.atwell
Rectangle select, not rectangle. :)

30b8T8B.gif

How I made Jennifer & Halle in Paint.net

My Gallery | My Deviant Art

"Rescuing one animal may not change the world, but for that animal their world is changed forever!" anon.

 
Link to comment
Share on other sites

Pixey thanks a lot for your response.

Yes the Grid Warp plugin may be something simillar to what i need.

 

Say i had a planet like this one:

example2.png

 

I'd like to stretch every ROW of pixels horizontally, so that the selection fits the edge of the canvas evenly.

 

example.png

 

Until it becomes a square with the same texture, identical at the middle, and evenly stretched up and down

Something i could not do with the Grid  Warp tool, but it would look something like this:

example3.png

OK not anything like this but i hope I'm making some sense.

It's important that every row of pixels is stretched evenly and tha tit fills the entire square.

Link to comment
Share on other sites

Many thank @David for the correction :) my brain is on a holiday today!
 
@Cheezl - is this what you are aiming for?
 
3k9OMee.png
 
The steps are here below.  Basically, as said before, The Rectangle Select Tool :RectangleSelectTool: should do the trick.
 
First use it to make your planet (image) as large as possible to fill your layer.
Then use the same tool to draw a rectangle, or a square, Invert the selection and press delete.
You will now have a rectangle, or square, with the image inside.

http://i.imgur.com/Rn3chPr.png

I hope this is what you were looking for :)

Edited by Pixey

30b8T8B.gif

How I made Jennifer & Halle in Paint.net

My Gallery | My Deviant Art

"Rescuing one animal may not change the world, but for that animal their world is changed forever!" anon.

 
Link to comment
Share on other sites

Ah. You want to do the opposite of DrumSkin.

How about this little beauty... http://forums.getpaint.net/index.php?/topic/23433-squirklewarp/

  • Upvote 1
Link to comment
Share on other sites

This is the typical case where you should write a CodeLab script because you provided the algorithm already:

 

>> It's important that every row of pixels is stretched evenly and tha tit fills the entire square.

void Render(Surface dst, Surface src, Rectangle rect)
{
    float CenterX = src.Width / 2f;

    // for each row
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        int x;

        // Determine the number of transparent pixels on the left side
        // Determine the scale factor which is (opaque pixels / max pixels)
        for (x = 0; x < CenterX; x++) 
        {
            if (src[x,y].A == 255) break;
        }
        float lScale = (CenterX - x) / CenterX;

        // Same for the right side
        for (x = src.Width - 1; x >= CenterX; x--)
        {
            if (src[x,y].A == 255) break;
        }
        float rScale = (x - CenterX) / CenterX;
        
        // Render the pixels of the row
        for (x = rect.Left; x < rect.Right; x++)
        {
            if (x < CenterX)
            {
                dst[x,y] = src.GetBilinearSample(CenterX - ((CenterX - x) * lScale),y);
            }
            else
            {
                dst[x,y] = src.GetBilinearSample(CenterX + ((x - CenterX) * rScale),y);
            }
        }
    }
}

So download CodeLab plugin, open it (Menu->Advanced->CodeLab), and replace the content of the editor with the script.

You will see the result immediately. And you can always optimze the algorithm in a way you like. :-)

 

post-79572-0-74357800-1406845624_thumb.j

  • Upvote 3

midoras signature.gif

Link to comment
Share on other sites

Yes indeed, Midora provided exactly what i was searching for. Thanks a lot :)

Since I am more of a programmer with a good understanding of algorithms, CodeLab seems to be more up my alley.

I had no idea you could actually do this.

 

Hehe yeah udDrumSkin :)

Also, Ego Eram Reputo, I'll check out the plugin you provided, though I hope I'll be using CodeLab a lot more from now on.

 

Everyone, thanks again for all of your replies! You've all been more than helpful. :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...