fast convert any bmp to rgb byte array - C#
Posted: 2018-11-12T15:29:38-07:00
Hello,
In my code I did:
MagickImage im = new MagickImage(<my file name>);
IPixelCollection pc = im.GetPixelsUnsafe();
...
The image is grayscale so it has 2 channels,
but I want to fast convert it to 3 colors (and save the binary data - only the byte array of rgb to file).
Also convert to 1 color.
How can I do that?
For grayscale image I did:
byte[] b = pc.GetPixelArea(...)
but b got values of "R" and "G" (but not value for "B").
Also, I want to write a small program in C#, that create a binary file for grayscale (or anything), and load the binary again - save part of it or load part of the file.
Maybe I can do as following (for loading), but I didn't see PixelMapping with two colors or one channel.
MagickReadSettings mr = new MagickReadSettings();
PixelStorageSettings ps = new PixelStorageSettings(imgWidth, imgHeight, StorageType.Char, PixelMapping.RGB);
Is there any good way to save to just binary file, and load it quickly (from/to any image format).
Need to resolve very big image files, even 100k x 1000k pixels (maybe jp2 is good for that), and program will not be out of memory.
I need also to load part of the big image (and also save part of the big file).
Thanks.
In my code I did:
MagickImage im = new MagickImage(<my file name>);
IPixelCollection pc = im.GetPixelsUnsafe();
...
The image is grayscale so it has 2 channels,
but I want to fast convert it to 3 colors (and save the binary data - only the byte array of rgb to file).
Also convert to 1 color.
How can I do that?
For grayscale image I did:
byte[] b = pc.GetPixelArea(...)
but b got values of "R" and "G" (but not value for "B").
Also, I want to write a small program in C#, that create a binary file for grayscale (or anything), and load the binary again - save part of it or load part of the file.
Maybe I can do as following (for loading), but I didn't see PixelMapping with two colors or one channel.
MagickReadSettings mr = new MagickReadSettings();
PixelStorageSettings ps = new PixelStorageSettings(imgWidth, imgHeight, StorageType.Char, PixelMapping.RGB);
Is there any good way to save to just binary file, and load it quickly (from/to any image format).
Need to resolve very big image files, even 100k x 1000k pixels (maybe jp2 is good for that), and program will not be out of memory.
I need also to load part of the big image (and also save part of the big file).
Thanks.