Jump to content

Resize Internal Selection


Recommended Posts

I want to resize something if it is bigger than X number of pixels to be equal to X number of pixels

now to be clear this is not resize the selection box the users sees but resizing a internal selection box i have defined(assuming it is in the selection box the user made)

is that possible?

 

Link to comment
Share on other sites

If I understand you... Possible. (Keeping this in mind: http://forums.getpaint.net/index.php?/topic/14566- of course)

You'll need to create your own surface to hold your resized image.

Then, you'll need to resize the image to that surface.

Here is a function to help you:

wrk[x,y] = src.GetBilinearSample(x * xfactor, y * yfactor);

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

If I understand you... Possible. (Keeping this in mind: http://forums.getpaint.net/index.php?/topic/14566- of course)

You'll need to create your own surface to hold your resized image.

Then, you'll need to resize the image to that surface.

Here is a function to help you:

 

wrk[x,y] = src.GetBilinearSample(x * xfactor, y * yfactor);

so that peice of code gets me a surface that contains only the bounding box of my supplied x, y ?

Edited by Zarklord
Link to comment
Share on other sites

Nope. That piece of code gets you ONE PIXEL. You'll need to iterate over your wrk surface and calculate each pixel you want. But, first you'll need to calculate an xfactor and yfactor that will give you the difference between the size of your wrk surface and the source surface selection.

I would highly recommend you read through all the tutorials listed here: http://forums.getpaint.net/index.php?/topic/109990-

  • Upvote 1

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

Though I'm not sure what the potential plugin is supposed to do, I'll offer two pieces of advice anyway.

 

First, the xfactor in BoltBait's comment is generally the reciprocal of the scaling factor (i.e., 1.0 / xscale). That's because you're not trying to transform a source pixlel into a destination pixel; you're trying to calculate which source pixel transforms into the given destination pixel.

 

Second, unless you want the scaling to be relative to the upper-left corner, you need to include an offset:

wrk[x, y] = src.GetBilinearSample(x * xfactor + xoffset, y * yfactor + yoffset);

The offsets can be precomputed as follows:

double xoffset = (1.0 - xfactor) * xcenter;
double yoffset = (1.0 - yfactor) * ycenter;

(xcenter, ycenter) is the point about which the expansion or contraction occurs.

Link to comment
Share on other sites

thx you so far with your help...

so the best way for you to help me is for me to explain what i am doing...
so for a game there are nameplates i am making now it is crucial that no nameplates say go over 580 pixels, this only matters for nameplates larger than 580 pixels

so what I need is:

a: if i have my start point(x:30, y:30) figure out my endpoint i would prefer to do this in code as it would be much simpler(rather than measurements because the spacing is random(well not really random, but say different for each letter(ie the pixels between 2 A's might be 2px but the spacing between AB might be 4px)...).

b:then resize if the width is greater than 580(this value might change but it should just be matter of updating a constant if I do it right) to 580(also for a special case resize height but the same principles should apply. right?).

c: move it on the dest surface positioning correctly this should be as simple as start drawing the pixels at pos x, y(whatever those may be) and iterating through the pixels...

 

EDIT i discovered g.MeasureString but the values are higher than they should be... Why?

Edited by Zarklord
Link to comment
Share on other sites

there...

 

So you only want to compress them in Y, not also in X?

 

How would you use it? Is each nameplate in a separate image, and you want to apply the plugin to the whole image, or are there several nameplates in a single image? If there are several, do you intend to make a selection around each nameplates, or is the plugin supposed to locate the individual nameplates and resize each one?

Link to comment
Share on other sites

So you only want to compress them in Y, not also in X?

 

How would you use it? Is each nameplate in a separate image, and you want to apply the plugin to the whole image, or are there several nameplates in a single image? If there are several, do you intend to make a selection around each nameplates, or is the plugin supposed to locate the individual nameplates and resize each one?

there could be nameplates that are two lines and i might want to compress them in Y...

and the idea is my plugin will draw the letters for the nameplate, resize the nameplate, position the nameplate efficiently(IE so that you could fit as any as possible on a canvas). then rinse, repeat for each name plate the user requests...

although there doesnt appear to be a way to get the width of the nameplate accuratley...

Link to comment
Share on other sites

Hello Zarklord, I hope I did not mislead you. I do not do any coding. I just took a printscreen of Toe_Head's Text Window effect and modified the "printscreen Image" into something that I would like. Toe_head2001 has published the code for the Tex window effect in GitHub.

 

Once again, sorry if I confused you. I just wanted to give an idea of how such effect could look.

Link to comment
Share on other sites

well the current problem i am having is not being able to select the text and only the text exactly it is always a couple pixels over...

What? Are you wanting to modify existing text, or is your effect also generating the text?

Please clearly communicate what you're wanting your effect to do. List the steps if you have to. I think everyone is a bit confused.

Link to comment
Share on other sites

What? Are you wanting to modify existing text, or is your effect also generating the text?

Please clearly communicate what you're wanting your effect to do. List the steps if you have to. I think everyone is a bit confused.

i cant get the dimenesions of the text to be able to resize

ie if i type NAMEPLATE and want to get the dimmensions of the word (IE x, y) in code but i cant.

as using measurestring and measurecharacterranges both return incorrect values

Link to comment
Share on other sites

Toe_head2001,

 

This is an example when I needed a tool that would fit a word into a square selection.  I wanted to create a sphere with a word using TR's Drum Skin effect. But in order to use it I had to fill a square selection with the word. I encountered some limitations with Paint.net's Text tool and because when I enlarged it to fit the square the text was so blury that I abandoned my project.

 

I just tested your Selection Text effect and the text is sharper I just needed to manually expand it a little bit so it would fill the square selection.

rainbow-text-tool-500c6f5.png

Link to comment
Share on other sites

Here's "Nameplate" with an outline representing the dimensions returned from MeasureString.

I would think 5 extra pixels on the left & right is negligible, especially when working with higher resolutions.

nameplate.png

A I am using a font called DFGMincho-SU it is Little Weird and the size is 105.4

so maybe but i remember the size being a quite a bit more than that and also the extra amount of pixels is a difference cause i need them to be exactly 580 if they are larger than 580(IE i am already scaling them down some i dont want to scale more than nessacary)

 

Edit: i measured one and the value was correct and another one was 6px off... so no accuracy

Edited by Zarklord
Link to comment
Share on other sites

In the example effect I attached, I forgot to change the StringFormat from the default, which adds 1/6 em to either side of the string.
In my "Nameplate" image, I remembered to change the StringFormat in order correct that behavior.
 
@@Zarklord, are you changing the StringFormat? StringFormat.GenericTypographic will remove the 1/6 em.

@@Eli, I updated that example effect, download it again if you want.

 

 

 

StringFormat.GenericTypographic:

nameplate.png

 

Default StringFormat:

nameplate2.png

Link to comment
Share on other sites

In the example effect I attached, I forgot to change the StringFormat from the default, which adds 1/6 em to either side of the string.

In my "Nameplate" image, I remembered to change the StringFormat in order correct that behavior.

 

@@Zarklord, are you changing the StringFormat? StringFormat.GenericTypographic will remove the 1/6 em.

@@Eli, I updated that example effect, download it again if you want.

 

 

 

StringFormat.GenericTypographic:

nameplate.png

 

Default StringFormat:

nameplate2.png

that is what i have unless there is something to do with the point in between font and stringformat(cause i have no idea what it is used for) then the values above are correct(for generic Typograph)...

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