public jpeg_copy_critical_parameters ( jpeg_compress_struct dstinfo ) : void | ||
dstinfo | jpeg_compress_struct | Target JPEG compression object. |
return | void |
public static string IncImageDCT(string fullPath) { string suffix = "testDCT"; var img = new Bitmap(fullPath); var width = img.Width; var height = img.Height; int hd = height / 8; int wd = width / 8; img.Dispose(); BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct(); System.IO.FileStream oFileStreamImage = new System.IO.FileStream(fullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); oJpegDecompress.jpeg_stdio_src(oFileStreamImage); oJpegDecompress.jpeg_read_header(true); BitMiracle.LibJpeg.Classic.jvirt_array<BitMiracle.LibJpeg.Classic.JBLOCK>[] JBlock = oJpegDecompress.jpeg_read_coefficients(); var block = JBlock[0].Access(0, hd); // accessing the element for (int i = 0; i < hd; i++) { for (int j = 0; j < wd; j++) { short t = block[i][j].data[0]; if ((t >= 0 && t % 2 == 1) || (t < 0 && t % 2 == 0)) { t--; } else if ((t >= 0 && t % 2 == 0) || (t < 0 && t % 2 == 1)) { t++; } block[i][j].data[0] = t; } } oJpegDecompress.jpeg_finish_decompress(); oFileStreamImage.Close(); //// string filenameNew = MyHelper.AppendFileName(fullPath, suffix); System.IO.FileStream objFileStreamMegaMap = System.IO.File.Create(filenameNew); BitMiracle.LibJpeg.Classic.jpeg_compress_struct oJpegCompress = new BitMiracle.LibJpeg.Classic.jpeg_compress_struct(); oJpegCompress.jpeg_stdio_dest(objFileStreamMegaMap); oJpegDecompress.jpeg_copy_critical_parameters(oJpegCompress); oJpegCompress.Image_height = height; oJpegCompress.Image_width = width; oJpegCompress.jpeg_write_coefficients(JBlock); oJpegCompress.jpeg_finish_compress(); objFileStreamMegaMap.Close(); oJpegDecompress.jpeg_abort_decompress(); return filenameNew; }