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