| |

VerySource

 Forgot password?
 Register
Search
View: 1220|Reply: 7

How to cut a PNG image

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-1 17:30:01
| Show all posts |Read mode
Now there is a PNG image, which needs to be cut into several PNGs of equal size. Is there any good way?
Reply

Use magic Report

0

Threads

55

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-5-17 16:30:01
| Show all posts
The memory data of the PNG image is divided into several equal memory blocks according to rows and columns.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-10 10:15:01
| Show all posts
The problem is that I don’t know what the distribution of memory data is. How can I ensure that the memory blocks I keep are continuous squares?
Unless there is an array to record the arrangement of pixels of PNG in memory, so by recording png[][] you can get the corresponding block pixels for saving, and it also involves the PNG compression algorithm.
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-25 17:00:01
| Show all posts
Convert it to BMP data, divide it into blocks, and then transfer it back.

What should the BMP data look like?
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-30 10:00:01
| Show all posts
png and bmp are similar, a large section of the head is all kinds of information of the picture, followed by the color data of each pixel (256-color palette, 24-bit ARGB), you can use GDI+

bitmap = new Bitmap(L"sample.png");
pixelFormat = bitmap->GetPixelFormat(); //such as PixelFormat24bppRGB, PixelFormat8bppIndexed
width = bitmap->GetWidth();
height = bitmap->GetHeight();

rect.X = 0;
rect.Y = 0;
rect.Width = width;
rect.Height = height;
bitmap->LockBits(rect, ImageLockModeWrite, pixelFormat, bitmapData); //Read the picture into bitmapData, and then you can operate

p = (byte *) bitmapData->Scan0; //bitmapData->Scan0 is the first pixel of the picture

You can deal with the above
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-30 12:45:01
| Show all posts
It’s OK to use GetPixel
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-20 20:30:01
| Show all posts
Which prawn introduced in more detail?
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-4 12:15:01
| Show all posts
I finally used the CImage class to handle it, which is more convenient
But thank you very much for the algorithm provided bymicjoy~ I will considermicjoyalgorithm to write my own after finishing the current project with FMC! !
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list