Click here to Skip to main content
15,867,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to get bitmap bits of each quadrant(1/4) of bitmap separately for splitting bitmap into 4.

What I have tried:

In BITMAPINFOHEADER, if I set as width and height as below and call CreateDIBSection I am able to get bits for first quadrant of bitmaps only. How to get bits for 2, 3, 4th quadrant?

BITMAPINFOHEADER bmh;
BITMAP bm;

bmh.bmWidth=bm.bmWidth/2;
bmh.bmHeight=bm.bmHeight/2;
Posted
Updated 11-Feb-21 0:02am

1 solution

You would have to create four bitmaps of the appropriate size, then draw the existing bitmap into them:
C#
using (Image large = Bitmap.FromFile(@"D:\Test data\BigImage.jpg"))
    {
    using (Image small = new Bitmap(large.Width / 2, large.Height / 2))
        {
        using (Graphics g = Graphics.FromImage(small))
            {
            g.DrawImage(large, 0.0f, 0.0f);
            small.Save(@"D:\Test Data\TopLeft.jpg", ImageFormat.Jpeg);
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900