Results 1 to 11 of 11
  1. #1
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    395
    Reputation
    23
    Thanks
    801
    My Mood
    Relaxed

    Why does my image get resized like this?

    Code:
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Windows.Forms;
    
    namespace Sprite
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private string dir = Directory.GetCurrentDirectory();
    
            private void Form1_Load(object sender, EventArgs e)
            {
                PictureBox sprite = new PictureBox();
                Bitmap img = new Bitmap(dir + "/lofiObj3.png");
                Rectangle section = new Rectangle(new Point(0, 0), new Size(8, 8));
                img = getImage(img, section, new Size(64, 64));
                sprite.Image = img;
                sprite.SizeMode = PictureBoxSizeMode.AutoSize;
                sprite.Top += 50;
                sprite.Left += 50;
                Controls.Add(sprite);
            }
    
            public Bitmap getImage(Bitmap source, Rectangle section, Size size)
            {
                // An empty bitmap which will hold the cropped image
                Bitmap cropped = new Bitmap(section.Width, section.Height);
    
                Graphics crop = Graphics.FromImage(cropped);
    
                // Draw the given area (section) of the source image
                // at location 0,0 on the empty bitmap (bmp)
                crop.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
                
                // An empty bitmap which will hold the resized image
                Bitmap resized = new Bitmap(size.Width, size.Height);
    
                Graphics resize = Graphics.FromImage(resized);
    
                // Resize the bitmap to a new size
                resize.InterpolationMode = InterpolationMode.NearestNeighbor;
                resize.DrawImage(cropped, new Rectangle(new Point(0, 0), resized.Size));
    
                return resized;
            }
    
        }
    }
    Why does my image look like this:



    When it should look like this (used nearest neighbor in paint.net):



     

  2. #2
    MadmanDev's Avatar
    Join Date
    Nov 2018
    Gender
    male
    Posts
    1
    Reputation
    10
    Thanks
    0
    use picturebox controls to control how it sort image to picturebox

  3. #3
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    395
    Reputation
    23
    Thanks
    801
    My Mood
    Relaxed
    Quote Originally Posted by MadmanDev View Post
    use picturebox controls to control how it sort image to picturebox
    It has nothing to do with the picture box, if I save the image it remains the same as how it is seen on the form.

  4. #4
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    395
    Reputation
    23
    Thanks
    801
    My Mood
    Relaxed
    bump ////////////

  5. #5
    ButtonHead's Avatar
    Join Date
    Nov 2018
    Gender
    male
    Posts
    7
    Reputation
    10
    Thanks
    0
    I don't understand the problem exactly?
    Are you saying it is because the image is cut off slightly at the top? Looking at your image, the potions Y coordinate is dead on 0. The comment says it starts a 0,0 but perhaps its off by 1 pixel. Try adding a 1pixel border around the image. If that isn't the problem then please elaborate on what the issue is that your having.

    Edit:
    Also, I'm reinstalling VS atm as i wiped my machine. When its done I'll take a look using the image.
    Last edited by ButtonHead; 11-30-2018 at 08:19 PM.

  6. #6
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    395
    Reputation
    23
    Thanks
    801
    My Mood
    Relaxed
    bump ////////////

  7. #7
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,978
    Reputation
    343
    Thanks
    4,310
    My Mood
    Cheeky
    Try resize.PixelOffsetMode = PixelOffsetMode.Half;

  8. #8
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    395
    Reputation
    23
    Thanks
    801
    My Mood
    Relaxed
    Quote Originally Posted by Hell_Demon View Post
    Try resize.PixelOffsetMode = PixelOffsetMode.Half;
    nope :/

  9. #9
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    395
    Reputation
    23
    Thanks
    801
    My Mood
    Relaxed
    bump//////////////

  10. #10
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    395
    Reputation
    23
    Thanks
    801
    My Mood
    Relaxed
    bump////////////////////

  11. #11
    Nutty1337's Avatar
    Join Date
    Feb 2019
    Gender
    male
    Location
    Toronto
    Posts
    17
    Reputation
    10
    Thanks
    0
    My Mood
    Angelic
    On the picturebox there's a setting to change the way the image will be resized

Similar Threads

  1. [Image] does anyone else see code like this
    By tdpo in forum General
    Replies: 10
    Last Post: 08-14-2015, 10:19 AM
  2. Replies: 5
    Last Post: 07-02-2013, 11:10 PM
  3. Why isn't there a game like this?
    By jonnyboy9985 in forum General Gaming
    Replies: 6
    Last Post: 09-08-2010, 04:12 AM
  4. why does speed gear get detected after the 2-4 games?
    By Reckless in forum Combat Arms Hacks & Cheats
    Replies: 10
    Last Post: 02-11-2009, 05:05 AM
  5. -_- Why does 'Working' Keep getting set to false.
    By radnomguywfq3 in forum C++/C Programming
    Replies: 5
    Last Post: 12-04-2007, 06:27 AM