How to change color of Image at runtime

前端 未结 3 1925
情话喂你
情话喂你 2020-12-05 22:02

I would like to know is there any way by which we can change the Image color at runtime. for e.g lets say I am having a JPG bind to an Image control of ASP.Net. Next I am ha

3条回答
  •  感情败类
    2020-12-05 23:00

    You also try this for web (asp.net) , you can ignore the logic but can see what getpixel & setpixel doing

     public string FileUpload( HttpPostedFileBase file )
      {
         Bitmap bmp = new Bitmap(file.InputStream);
         string valid = "";
    
         for(int i = 0; i < bmp.Width; i++) {
            for(int j = 0; j < bmp.Height; j++) {
               if(bmp.GetPixel(i , j).B < 20) {
                  if(bmp.GetPixel(i , j).B == bmp.GetPixel(i , j).G &&
                     bmp.GetPixel(i , j).B == bmp.GetPixel(i , j).R) {
                     valid = valid + bmp.GetPixel(i , j). + "
    "; bmp.SetPixel(i , j , Color.DarkGreen); } } } } SaveImage(bmp); return valid; } private void SaveImage( Bitmap newbmp ) { string path = Path.Combine(Server.MapPath("~/Images") , "ScaledImage.jpeg"); newbmp.Save(path , System.Drawing.Imaging.ImageFormat.Jpeg); }

提交回复
热议问题