• 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

    • You are like that narcissistic moron and his name is Paul Thurrott.
    • WhatsApp document scanning gets closer to launch as more beta testers get access by Paul Hill Meta looks as though it’s getting closer to releasing WhatsApp’s native document scanner on Android because more people are now reporting they have access in the beta. This will give users a privacy-friendly way to snap photos of documents and automatically convert them to PDF ready for sharing. According to WABetaInfo, the feature comes with two modes: manual and automatic. The manual capture gives users more control over the process allowing them to adjust positioning and lighting to get the best quality scan. Automatic mode on the other hand automatically detects the edge of your document on its own and snaps the image without too much user input, making it faster and easier. Once the picture is taken, WhatsApp automatically converts it to a PDF file so that it can be shared and opened easily by the recipient. The file can be sent within private chats or group conversations. The entire scanning and conversion process takes place locally on your device, using Android’s built-in API for snapping documents. The document itself is also only stored locally until you decide to send it. Just like other WhatsApp messages, these scans are secured with end-to-end encryption when you send them to recipients. The only privacy risk is the user sending the PDF to the wrong person. The new feature was first noticed for Android a few weeks ago and with the latest beta it’s rolling out to more people. Once Meta has tested it across a wide array of devices, we will likely see it land for people on the stable version of WhatsApp. In recent weeks, we have also seen that Meta is testing new chat color themes in the beta releases. That feature doesn’t seem to have filtered down to the stable version yet, so be on the lookout for that too if that’s of interest to you.
  • Recent Achievements

    • Collaborator
      Mighty Pen went up a rank
      Collaborator
    • Week One Done
      emptyother earned a badge
      Week One Done
    • Week One Done
      DarkWun earned a badge
      Week One Done
    • Very Popular
      valkyr09 earned a badge
      Very Popular
    • Week One Done
      suprememobiles earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      568
    2. 2
      +FloatingFatMan
      188
    3. 3
      ATLien_0
      177
    4. 4
      Skyfrog
      111
    5. 5
      Xenon
      110
  • Tell a friend

    Love Neowin? Tell a friend!