I have captured a JPG image using a Webcam in C# and have stored it in a folder.
Now I want to convert it to an 8-bit PNG image.
I checked all over internet and Stack Overflow, but none of the proposed solutions work for me.
Here is what I am currently using:
Bitmap img = new Bitmap(imgPath);
Bitmap img8 = new Bitmap(imgW, imgH, PixelFormat.Format16bppRgb565);
for (int I = 0; I <= img.Width - 1; I++)
for (int J = 0; J <= img.Height - 1; J++)
img8.SetPixel(I, J, img.GetPixel(I, J));
However, this throws the following exception:
SetPixel is not allowed for indexed pixel images.
You could try to use ImageMagick , it contains a utility to convert files. You can use either the command line interface or a .Net connector like magick.Net .
Using the command line, you could launch a process that runs the following command:
convert [yourfile.jpg] -depth 8 [yourfile.png]
That's probably overkill, but that's the only option I know to work on images.
No i cant use Gif. BUt can use TIFF.
Image orgBmp = Image.FromFile(@"fname.jpg");
var tiffEncoder = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()
.First(e => e.FormatDescription == "TIFF");
EncoderParameters parameters = new EncoderParameters(1);
parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, (long)ColorDepth.Depth8Bit);
orgBmp.Save(@"fname.tif", tiffEncoder, parameters);
you have to perform some programming by your self. you can find an example logic and code here http://codingresolved.com/discussion/2185/save-png-image-as-8bit-format-in-c
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.