locked
Change Bitmap Resolution and Turn Black & White RRS feed

  • Question

  • User-711701769 posted

    i use this method to resize bitmaps.

    Bitmap OriginalBM = (Bitmap)Bitmap.FromStream(fileUploader.PostedFile.InputStream);
                Size newSize = new Size(300, 500);
                Bitmap Resizebm = new Bitmap(OriginalBM, newSize);
                Resizebm.Save(HttpContext.Current.Server.MapPath(yourPath) + yourImage, ImageFormat.Jpeg);
                OriginalBM.Dispose();

    My question is how can i Change Bitmap Resolution and Turn Black & White?


    Thursday, September 2, 2010 4:33 AM

Answers

  • User-525215917 posted

    Using this code example you can create grayscale images.

    public Bitmap GrayScale(Bitmap Bmp) 
    {
        int rgb;
        Color c;
        
        for (int y = 0; y <Bmp.Height; y++)
            for (int x = 0; x <Bmp.Width; x++)
            {
                c = Bmp.GetPixel(x, y);
                rgb = (int)((c.R + c.G + c.B) / 3);
                Bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
            }
        return Bmp;
    }



    You can read more about this example from my blog posting How to create grayscale images on .NET.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 2, 2010 6:29 AM

All replies

  • User-525215917 posted

    Using this code example you can create grayscale images.

    public Bitmap GrayScale(Bitmap Bmp) 
    {
        int rgb;
        Color c;
        
        for (int y = 0; y <Bmp.Height; y++)
            for (int x = 0; x <Bmp.Width; x++)
            {
                c = Bmp.GetPixel(x, y);
                rgb = (int)((c.R + c.G + c.B) / 3);
                Bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
            }
        return Bmp;
    }



    You can read more about this example from my blog posting How to create grayscale images on .NET.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 2, 2010 6:29 AM
  • User-711701769 posted

    thanks digimortal


    Thursday, September 2, 2010 8:45 AM