Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

PictureBox - Resizing an image and making it pixelate?

I download an image to a PictureBox using
PHP Code

<?php 
pictureBox1
.ImageLocation = "url"; 

It downloads an image that's 64 by 32, but my PictureBox is 256 by 128.
I have the SizeMode property set to StretchImage.

StretchImage works fine, except it blurs the edges between pixels, I need this to look pixely.

I've read a lot of answers to this questions, they all say that you need to use the Graphics class but I haven't seen any code example that have worked.

Can someone here give me the code to make the result look pixely?

Thanks a bunch 🙂
/* No comment */
What you do is basically every pixel times 4, but since we have modern displays it doesn't look pixelated but blurry indeed.

If you want your image to be pixelated you'll have to delete (or skip) pixels, this is quite interesting. let me try something out.

EDIT: Could you PM me or link the image here ? So I got something to work with...
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
(Sep 29, 2012 04:01 PM)n0pcode Wrote:  What you do is basically every pixel times 4, but since we have modern displays it doesn't look pixelated but blurry indeed.

If you want your image to be pixelated you'll have to delete (or skip) pixels, this is quite interesting. let me try something out.

EDIT: Could you PM me or link the image here ? So I got something to work with...

Alright, cool.
Hope you come up with something :)
/* No comment */
I was bored so I came up with something, not sure if it's the best way to do this but I hope it'll help.

Code
private Image pixelate(Image img, int finalWidth, int finalHeight)
  {
    Bitmap b = (Bitmap)img;
    Size ratio = new Size(finalWidth / b.Width, finalHeight / b.Height);
    Bitmap bp = new Bitmap(b.Width * ratio.Width, b.Height * ratio.Height);
    Graphics g = Graphics.FromImage(bp);
    for (int y = 0; y < b.Height; y++)
    {
    for (int x = 0; x < b.Width; x++)
    {
    g.FillRectangle(new SolidBrush(b.GetPixel(x, y)), new Rectangle(new Point(x * ratio.Width, y * ratio.Height), ratio));
    }
    }
    return (Image)bp;
  }

Here's comparsion
[Image: 19Rbt]
(Sep 29, 2012 04:32 PM)Pussy Cat Wrote:  I was bored so I came up with something, not sure if it's the best way to do this but I hope it'll help.

Code
private Image pixelate(Image img, int finalWidth, int finalHeight)
  {
    Bitmap b = (Bitmap)img;
    Size ratio = new Size(finalWidth / b.Width, finalHeight / b.Height);
    Bitmap bp = new Bitmap(b.Width * ratio.Width, b.Height * ratio.Height);
    Graphics g = Graphics.FromImage(bp);
    for (int y = 0; y < b.Height; y++)
    {
    for (int x = 0; x < b.Width; x++)
    {
    g.FillRectangle(new SolidBrush(b.GetPixel(x, y)), new Rectangle(new Point(x * ratio.Width, y * ratio.Height), ratio));
    }
    }
    return (Image)bp;
  }

Here's comparsion
[Image: 19Rbt]

It works like a dream, thanks man :D
Check your rep
/* No comment */
Can I asked why you needed to do this? It just seems like something dumb unless you are doing what I think your doing.
(Sep 29, 2012 04:54 PM)Linux. Wrote:  Can I asked why you needed to do this? It just seems like something dumb unless you are doing what I think your doing.

What do you think I'm doing? I wanna know 😝
I'll post a thread about this project in a minute.
/* No comment */
Some type of color detection program or something? Maybe something to fix the pixels so they fix themselves when re-sized.
(Sep 29, 2012 04:57 PM)Linux. Wrote:  Some type of color detection program or something? Maybe something to fix the pixels so they fix themselves when re-sized.

It's actually a skin stealer for Minecraft :P
/* No comment */
(Sep 29, 2012 04:59 PM)Quad Wrote:  It's actually a skin stealer for Minecraft :P

Really? How the hell? Add me on Skype austin--sweat 🤝
(Sep 29, 2012 04:59 PM)Quad Wrote:  It's actually a skin stealer for Minecraft :P

May i ask why you need to pixelate an image if you want to steal a skin? You mean from other people? if so you can just download the image from http://minecraft.net/skin/PersonsName*can use textbox to change if wanted*.png, course then again that's when minecraft.net is actually up :P
(Sep 29, 2012 06:29 PM)Debroski Wrote:  May i ask why you need to pixelate an image if you want to steal a skin? You mean from other people? if so you can just download the image from http://minecraft.net/skin/PersonsName*can use textbox to change if wanted*.png, course then again that's when minecraft.net is actually up :P

I want to display it nicely. msg ...
/* No comment */


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by C++Dec 29, 2019 06:16 PM 16 831 Dec 29, 2019 06:16 PM
Last Post: DNA
[.NET] by ShapelessSep 27, 2019 12:15 PM 16 614 Sep 27, 2019 12:15 PM
Last Post: 0xDEAD10CC
[Python] by DistrictApr 7, 2019 03:14 AM 4 230 Apr 7, 2019 03:14 AM
Last Post: lockhead