Zarklord Posted July 30, 2016 Share Posted July 30, 2016 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? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted July 30, 2016 Share Posted July 30, 2016 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); Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Zarklord Posted July 30, 2016 Author Share Posted July 30, 2016 (edited) 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 July 30, 2016 by Zarklord Quote Link to comment Share on other sites More sharing options...
BoltBait Posted July 30, 2016 Share Posted July 30, 2016 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- 1 Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted July 31, 2016 Share Posted July 31, 2016 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. Quote Link to comment Share on other sites More sharing options...
Zarklord Posted July 31, 2016 Author Share Posted July 31, 2016 (edited) 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 July 31, 2016 by Zarklord Quote Link to comment Share on other sites More sharing options...
MJW Posted August 1, 2016 Share Posted August 1, 2016 I'm still not clear on what you want to achieve. A before and after example might help. Quote Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 I'm still not clear on what you want to achieve. A before and after example might help. there... Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted August 1, 2016 Share Posted August 1, 2016 You can use FitSurface to resize the image to the size of your custom surface. Ex: Surface customSurface = new Surface(customWidth, customHeight); customSurface.FitSurface(ResamplingAlgorithm.Fant, sourceSurface); Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
MJW Posted August 1, 2016 Share Posted August 1, 2016 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? Quote Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 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... Quote Link to comment Share on other sites More sharing options...
Eli Posted August 1, 2016 Share Posted August 1, 2016 It may have nothing to do with the thread but an effect that can fit text to a selection would be cool. (I modified Toe_head's2001 "Text Window" interface) Quote Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 It may have nothing to do with the thread but an effect that can fit text to a selection would be cool. (I modified Toe_head's2001 "Text Window" interface) that is basicaly what i want... Quote Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 It may have nothing to do with the thread but an effect that can fit text to a selection would be cool. (I modified Toe_head's2001 "Text Window" interface) could i see the code and the plugin? Quote Link to comment Share on other sites More sharing options...
Eli Posted August 1, 2016 Share Posted August 1, 2016 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. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted August 1, 2016 Share Posted August 1, 2016 Did you not try using FitSurface, as I described in my earlier post? It does what you want. Here's a basic example I threw together.SelectionText.zip Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 Did you not try using FitSurface, as I described in my earlier post? It does what you want. Here's a basic example I threw together. SelectionText.zip 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... Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted August 1, 2016 Share Posted August 1, 2016 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. Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 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 Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted August 1, 2016 Share Posted August 1, 2016 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. Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Eli Posted August 1, 2016 Share Posted August 1, 2016 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. Quote Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 (edited) 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. 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 August 1, 2016 by Zarklord Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted August 1, 2016 Share Posted August 1, 2016 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: Default StringFormat: Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Zarklord Posted August 1, 2016 Author Share Posted August 1, 2016 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: Default StringFormat: 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)... Quote Link to comment Share on other sites More sharing options...
Eli Posted August 1, 2016 Share Posted August 1, 2016 (edited) Thanks Toe_Head2001, I will add you to my Christmas tree. Edited August 2, 2016 by Eli Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.