简体   繁体   中英

Picture is 10x bigger in datastorage after manipulation

I'm trying to detect some green text in an picture and then manipulate the pixels under the text.

To do this I load the picture of the map (without text) and the manipulated picture. Move through the matrix checking the RGB-values and after the work is done I save the bitmap sn a .jpg again (under new name).

Problem is: the loaded pictures are about 3mb in storage size. The new saved picture has 30mb.

Same width/height and DPI. Just the color-depth is 1 byte higher (24bit -> 32bit). Never the less, this can't be the 10x factor.

Anybody knows what happens ?

Or the more interesting thing: how can I save the new bitmap with just 3mb ?

Thanks for your answers, -LD-

CODE:

// no text, picture shows a map
Bitmap MapBitmap = new Bitmap("C:\\Users\\LD\\Desktop\\Karte\\Map.jpg");    
// with green text
Bitmap OriginalBitmap = new Bitmap("C:\\Users\\LD\\Desktop\\Karte\\Original.jpg");  
// manipulated text
Bitmap NeueBitmap = new Bitmap(OriginalBitmap.Width,OriginalBitmap.Height); 

// move throug matix
for (int x = 0; x < OriginalBitmap.Width; x++)
{
   for (int y = 0; y < OriginalBitmap.Height; y++)
   {
      progressBar1.Value = x * 10000 / OriginalBitmap.Width;  // show progress
      Color OriginalColor = OriginalBitmap.GetPixel(x, y);
      int r = OriginalColor.R;    // for later use
      int g = OriginalColor.G;
      int b = OriginalColor.B;
      Color MapColor = MapBitmap.GetPixel(x, y);
      int R = MapColor.R;         // for later use
      int G = MapColor.G;
      int B = MapColor.B;

      if ((g/1.5)  > r && (g/1.5)  > b)
      {   // check the green-value compared to the others
         Color NeueColor = Color.FromArgb((R + 20), (G + 20), (B + 20));
         NeueBitmap.SetPixel(x, y, NeueColor);
      }
      else
      {
         Color NeueColor = Color.FromArgb(R, G, B);
         NeueBitmap.SetPixel(x, y, NeueColor);
      }
   }
}
NeueBitmap.Save("C:\\Users\\LD\\Desktop\\Karte\\Neu2.jpg");

Specify a format in the appropriate NeueBitmap.Save() overload; as it stands it will default to .PNG with a .JPG extension.

NeueBitmap.Save("C:\\Users\\LD\\Desktop\\Karte\\Neu2.jpg", ImageFormat.Jpeg);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM