Bitmap deep copy changing PixelFormat

前端 未结 2 1633
忘掉有多难
忘掉有多难 2021-01-26 03:53
Bitmap img = new Bitmap(\"C:\\\\temp\\\\images\\\\file.jpg\");

img.PixelFormat is Format24bppRgb

when I am doing deep copy

Bit         


        
2条回答
  •  日久生厌
    2021-01-26 04:58

    You can clone the bitmap like this, which will create a deep copy:

    Bitmap img = new Bitmap("C:\\temp\\images\\file.jpg");
    
    // Clone the bitmap.
    Rectangle cloneRect = new Rectangle(0, 0, img.Width, img.Height);
    System.Drawing.Imaging.PixelFormat format =
        img.PixelFormat;
    Bitmap img2 = img.Clone(cloneRect, format);
    

提交回复
热议问题