• 0

[C#] Stretch image vertically


Question

I'm loading this image from Properties.Resources and then clone some part of it to another image and then I draw it on the form in the Paint method. I want this image to stretched vertically but for some reason it's not being stretched like it was repeating itself (which I want), it looks "stretched".

This is my code:

Bitmap SKIN = new Bitmap(Properties.Resources.Skin);
System.Drawing.Imaging.PixelFormat format = SKIN.PixelFormat;
Bitmap iLeft = SKIN.Clone(new Rectangle(0, 10, 5, 15), format);

And on the Paint method:

e.Graphics.DrawImage(this.iLeft, 0, 6, 5, this.cHeight - 15);

And this is how it looks:

1120905673Untitled1.png

Basically, the cloned image is 5 pixels wide and 1 pixel high and I just want it to repeat it self without that "softness" you see on the image.

P.S: Sorry for my bad English on this post, I'm just very tired and sleepy :p

Link to comment
https://www.neowin.net/forum/topic/604612-c-stretch-image-vertically/
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Now that I've applied this to to project, this solution almost worked... maybe I did something wrong. Basically I had a tiny template image where I would clone parts of that image to create a border. I would just need 4 images (not counting with the corners), 2 for the horizontal borders (1px wide) and 2 for the vertical borders (1px height) and then stretch those images to fill the space necessary. For some reason, the op and left borders worked fine but the right and bottom ones didn't. When I resized the form, the pattern for the bottom and right border changed and that wasn't acceptable for what I want to do. I don't know if I did something wrong or not but I found a different solution:

ImageAttributes Attributes = new ImageAttributes();
Attributes.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile);
e.Graphics.DrawImage(IMAGE, DESTINATION_RECTANGLE, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, GraphicsUnit.Pixel, Attributes);

Something like this and it worked fine, no more blurred edge and no more moving pattern.

  • 0
  Nazgulled said:
Now that I've applied this to to project, this solution almost worked... maybe I did something wrong. Basically I had a tiny template image where I would clone parts of that image to create a border. I would just need 4 images (not counting with the corners), 2 for the horizontal borders (1px wide) and 2 for the vertical borders (1px height) and then stretch those images to fill the space necessary. For some reason, the op and left borders worked fine but the right and bottom ones didn't. When I resized the form, the pattern for the bottom and right border changed and that wasn't acceptable for what I want to do. I don't know if I did something wrong or not but I found a different solution:

ImageAttributes Attributes = new ImageAttributes();
Attributes.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile);
e.Graphics.DrawImage(IMAGE, DESTINATION_RECTANGLE, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, GraphicsUnit.Pixel, Attributes);

Something like this and it worked fine, no more blurred edge and no more moving pattern.

Sorry for bumping such an old thread but I have encountered the same problem Nazgulled described above me.

I was wondering how he solved it since the solution he posted didn't make sense to me. I tried tweaking it in all different sorts of ways but I can't figure it out.

Please help :)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Microsoft changes hit Teams Android devices: Disable Entra ID policy to restore sign-in by Paul Hill As part of its Secure Future Initiative, Microsoft has deployed a new Entra ID Conditional Access policy targeting Device Code Flow authentication. Unfortunately, it has led some Microsoft Teams-certified Android devices (Teams Rooms on Android, Teams Phones, Teams Panels, and Teams Displays) to be logged out and signing back in can be a bit fiddly so guidance has been shared. Microsoft said that it shared previous guidance which explained how to exclude Android devices, but it seems some admins didn’t catch this as many devices were not excluded and have been signed out. It’s important to realize that this is not a bug, it’s a security feature. However, the move could have been better communicated. To sign the devices back in, you can do so manually. However, if the devices are remote you’ll need to follow these steps: By disabling the “Block device code flow” policy in step 1, it will change everything back to how it was before Microsoft decided to enable it to boost security. This will allow you to get those affected Android devices logged back in again. Also pay special attention to step 2 which says you might need to reboot your device three times. Once you have your Android devices logged in again, it’s probably a good idea to follow Microsoft’s previous guidance and add these to an exclusion list before re-enabling the “Block device code flow” policy. Microsoft recommends only allowing DCF where it’s absolutely necessary and then blocking it elsewhere. The best thing to do is to add your Teams Android device to the exclusion list - this will allow these devices to operate normally, while boosting overall security. If you’re an admin and have been impacted by this, be sure to take proactive measures to avoid disruptions in the future.
    • Can someone help me with writing a batchfile using notepad to tell me to start a vpn plz? I would greatly appreciate any help  
    • Yeah define not catching up then to see the next part of this then
    • RoboForm 9.7.7 by Razvan Serea RoboForm is the top-rated Password Manager and Web Form Filler that completely automates password entering and form filling. RoboForm makes logging into Web sites and filling forms faster, easier, and more secure. RoboForm memorizes and securely stores each user name and password the first time you log into a site, then automatically supplies them when you return. RoboForm's powerful Logins feature eliminates the manual steps of logging into any online account. With just one click RoboForm will navigate to a Web site, enter your username and password and click the submit button for you. Completing long registration or checkout forms is also a breeze. Simply click on your RoboForm Identity and RoboForm fills-in the entire form for you. You no longer need to remember all your passwords. You remember one Master Password, and RoboForm remembers the rest. This allows you to use stronger passwords, making your online experience more secure. RoboForm uses strong AES encryption for complete data security. The all new RoboForm comes with Chrome and Safari browser support, iPhone/iPad and Android support, as well a brand new RoboForm Everywhere license for use on unlimited computers and mobile devices. RoboForm 9.7.7 changelog: Show RF Desktop unlock UI when user selects "Unlock" in RF Desktop UI. Fixed blank icon appeared in the Windows taskbar for RF Editor. Miscellaneous bug fixes. Download: RoboForm 9.7.7 | 42.2 MB (Free, paid upgrade available) View: RoboForm Website Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • LG G5 was the last memorable phone I had. The Samsung and Pixels and have had since have been disappointing and boring.
  • Recent Achievements

    • Reacting Well
      SteveJaye earned a badge
      Reacting Well
    • One Month Later
      MadMung0 earned a badge
      One Month Later
    • One Month Later
      Uranus_enjoyer earned a badge
      One Month Later
    • Week One Done
      Philsl earned a badge
      Week One Done
    • Week One Done
      Jaclidio hoy earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      439
    2. 2
      ATLien_0
      157
    3. 3
      +FloatingFatMan
      149
    4. 4
      Nick H.
      64
    5. 5
      +thexfile
      62
  • Tell a friend

    Love Neowin? Tell a friend!