//按下快捷键时被调用的方法 public void CallBack() { //MessageBox.Show("快捷键被调用!"); DateTime dt = DateTime.Now; var Stime = dt.ToString("yyyyMMddhhmmssfff"); for (int k = 0; k < MyPNum; k++) { Mybmp[k] = new Bitmap(MyLen, MyWid, PixelFormat.Format24bppRgb); Graphics g1 = Graphics.FromImage(Mybmp[k]); g1.CopyFromScreen(new Point(0, 0), new Point(0, 0), Mybmp[k].Size); MemoryStream ms = new MemoryStream(); Mybmp[k].Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); byte[] bytes = ms.GetBuffer(); Stream stream = new FileStream(Stime + ".jyf", FileMode.Append, FileAccess.Write, FileShare.None); BinaryWriter binStream = new BinaryWriter(stream); binStream.Write(bytes); binStream.Close(); stream.Close(); float[,] yArray = new float[Mybmp[k].Width, Mybmp[k].Height]; float[,] cbArray = new float[Mybmp[k].Width, Mybmp[k].Height]; float[,] crArray = new float[Mybmp[k].Width, Mybmp[k].Height]; float[,] aArray = new float[Mybmp[k].Width, Mybmp[k].Height]; BitmapToAYCbCrArrays(Mybmp[k], aArray, yArray, cbArray, crArray); Biorthogonal53Wavelet2D wavelet = new Biorthogonal53Wavelet2D(Mybmp[k].Width, Mybmp[k].Height); //System.Threading.Thread.Sleep(100); } Mybmp[0].Save("BMP.bmp", System.Drawing.Imaging.ImageFormat.Bmp); MessageBox.Show("截屏SUCCESS"); }
private static void applyAdaptiveDeadzone (float[,] array, int numCoeffs) { int width = array.GetLength (0); int height = array.GetLength (1); Biorthogonal53Wavelet2D wavelet53 = new Biorthogonal53Wavelet2D (width, height); OrderWavelet2D waveletOrder = new OrderWavelet2D (width, height); wavelet53.EnableCaching = true; waveletOrder.EnableCaching = true; wavelet53.TransformIsotropic2D (array); //Reverse the ordering of the coefficients waveletOrder.BacktransformIsotropic2D (array); //Use numCoeffs cofficient out of 64 (8x8) -> for e.g. numCoeffs = 5 this //means a compression to 7,8% of the original size waveletOrder.CropCoefficients (array, 7, 8); waveletOrder.TransformIsotropic2D (array); wavelet53.BacktransformIsotropic2D (array); }
private static void applyAdaptiveDeadzone(float[,] array, int numCoeffs) { int width = array.GetLength(0); int height = array.GetLength(1); Biorthogonal53Wavelet2D wavelet53 = new Biorthogonal53Wavelet2D(width, height); OrderWavelet2D waveletOrder = new OrderWavelet2D(width, height); wavelet53.EnableCaching = true; waveletOrder.EnableCaching = true; wavelet53.TransformIsotropic2D(array); //Reverse the ordering of the coefficients waveletOrder.BacktransformIsotropic2D(array); //Use numCoeffs cofficient out of 64 (8x8) -> for e.g. numCoeffs = 5 this //means a compression to 7,8% of the original size waveletOrder.CropCoefficients(array, 7, 8); waveletOrder.TransformIsotropic2D(array); wavelet53.BacktransformIsotropic2D(array); }
private static void applyAdaptiveShapening(float[,] array, float position) { int width = array.GetLength(0); int height = array.GetLength(1); Biorthogonal53Wavelet2D wavelet53 = new Biorthogonal53Wavelet2D(width, height); OrderWavelet2D waveletOrder = new OrderWavelet2D(width, height); wavelet53.EnableCaching = true; waveletOrder.EnableCaching = true; wavelet53.TransformIsotropic2D(array); //Reverse the ordering of the coefficients waveletOrder.BacktransformIsotropic2D(array); float[] scale = new float[8 * 8]; for (int x = 0; x < 8 * 8; x++) { scale [x] = 1.0f + 2.0f / ((position - x) * (position - x) + 1.0f); } waveletOrder.ScaleCoefficients(array, scale, 8); waveletOrder.TransformIsotropic2D(array); wavelet53.BacktransformIsotropic2D(array); }
public static void Main(string[] args) { Bitmap bmp = new Bitmap("../../sample.png"); Bitmap bmp2 = new Bitmap(2 * bmp.Width, 2 * bmp.Height, PixelFormat.Format32bppArgb); float[,] yArray2 = new float[bmp2.Width, bmp2.Height]; float[,] cbArray2 = new float[bmp2.Width, bmp2.Height]; float[,] crArray2 = new float[bmp2.Width, bmp2.Height]; float[,] aArray2 = new float[bmp2.Width, bmp2.Height]; ImageArrayConverter.BitmapToAYCbCrArrays(bmp, aArray2, yArray2, cbArray2, crArray2); Biorthogonal53Wavelet2D wavelet = new Biorthogonal53Wavelet2D(bmp.Width, bmp.Height); Biorthogonal53Wavelet2D wavelet2 = new Biorthogonal53Wavelet2D(bmp2.Width, bmp2.Height); wavelet.TransformIsotropic2D(aArray2); wavelet.TransformIsotropic2D(yArray2); wavelet.TransformIsotropic2D(cbArray2); wavelet.TransformIsotropic2D(crArray2); wavelet2.BacktransformIsotropic2D(aArray2); wavelet2.BacktransformIsotropic2D(yArray2); wavelet2.BacktransformIsotropic2D(cbArray2); wavelet2.BacktransformIsotropic2D(crArray2); for (int y = 0; y < bmp2.Height; y++) { for (int x = 0; x < bmp2.Width; x++) { aArray2[x, y] *= 4.0f; yArray2[x, y] *= 4.0f; cbArray2[x, y] *= 4.0f; crArray2[x, y] *= 4.0f; } } ImageArrayConverter.AYCbCrArraysToBitmap(aArray2, yArray2, cbArray2, crArray2, bmp2); bmp2.Save("test.png", ImageFormat.Png); }
public static void SaveAsFile(string sFile, ref int[,] rgbArray, int width, int height, int quality) { int size = width * height; int numRemainingY = quality * size / 100; int numRemainingCg = quality * size / 25; int numRemainingCo = quality * size / 25; int newWidth, newHeight; // int[,] rgbArray = new int[width, height]; // RGBColor.FillRGBArrayFromBitmap(bmp, ref rgbArray); FileStream fs = new FileStream(sFile, FileMode.Create, FileAccess.Write, FileShare.None); MemoryStream ms = new MemoryStream(); newWidth = IntegerMath.ToPowerOf2(width); newHeight = IntegerMath.ToPowerOf2(height); float[,] imgOrgY = new float[width, height]; float[,] imgOrgCg = new float[width, height]; float[,] imgOrgCo = new float[width, height]; float[,] imgY = new float[newWidth, newHeight]; float[,] imgCg = new float[newWidth, newHeight]; float[,] imgCo = new float[newWidth, newHeight]; int[,] imgIY = new int[newWidth, newHeight]; int[,] imgICg = new int[newWidth, newHeight]; int[,] imgICo = new int[newWidth, newHeight]; //YCgCoColor.RGBArrayToYCgCoArrays(ref rgbArray, width, height, ref imgOrgY, ref imgOrgCg, ref imgOrgCo); YCbCrColor.RGBArrayToYCbCrArrays(ref rgbArray, width, height, ref imgOrgY, ref imgOrgCg, ref imgOrgCo); ArrayHelper2D.ResizeArray2D(ref imgOrgY, ref imgY, width, height, newWidth, newHeight, ArrayHelper2D.ResizeFilter.NONE_CLAMP); ArrayHelper2D.ResizeArray2D(ref imgOrgCg, ref imgCg, width, height, newWidth, newHeight, ArrayHelper2D.ResizeFilter.NONE_CLAMP); ArrayHelper2D.ResizeArray2D(ref imgOrgCo, ref imgCo, width, height, newWidth, newHeight, ArrayHelper2D.ResizeFilter.NONE_CLAMP); Biorthogonal53Wavelet2D wavelet = new Biorthogonal53Wavelet2D(newWidth, newHeight, 8, 8, true); wavelet.TransformIsotropic2D(ref imgY); wavelet.TransformIsotropic2D(ref imgCg); wavelet.TransformIsotropic2D(ref imgCo); ArrayHelper2D.RemoveSmallestCoefficients2D(ref imgY, newWidth, newHeight, numRemainingY); ArrayHelper2D.RemoveSmallestCoefficients2D(ref imgCg, newWidth, newHeight, numRemainingCg); ArrayHelper2D.RemoveSmallestCoefficients2D(ref imgCo, newWidth, newHeight, numRemainingCo); //simple quantification float quant = 1.0f / (float)((100.0f - quality) + 1.0f); for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { imgY[x, y] *= quant; imgCg[x, y] *= quant; imgCo[x, y] *= quant; } } ArrayHelper2D.ConvertFloatToInt(ref imgY, ref imgIY, newWidth, newHeight); ArrayHelper2D.ConvertFloatToInt(ref imgCg, ref imgICg, newWidth, newHeight); ArrayHelper2D.ConvertFloatToInt(ref imgCo, ref imgICo, newWidth, newHeight); BinaryWriter writer = new BinaryWriter(ms); writer.Write(width); writer.Write(height); writer.Write(quality); for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { writer.Write(imgIY[x, y]); writer.Write(imgICg[x, y]); writer.Write(imgICo[x, y]); } } writer.Close(); byte[] buffer = ms.GetBuffer(); byte[] compressed = Memory.CompressBuffer(ref buffer); fs.Write(compressed, 0, compressed.Length); fs.Close(); }
public static int[,] LoadFromFile(string sFile, ref int width, ref int height) { FileStream fs = new FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read); MemoryStream ms = new MemoryStream(); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); byte[] decompressed = Memory.DecompressBuffer(ref buffer); ms.Write(decompressed, 0, (int)decompressed.Length); ms.Seek(0, 0); fs.Close(); BinaryReader br = new BinaryReader(ms); //int width, height; int newWidth, newHeight; width = br.ReadInt32(); height = br.ReadInt32(); int quality = br.ReadInt32(); newWidth = IntegerMath.ToPowerOf2(width); newHeight = IntegerMath.ToPowerOf2(height); int[,] imgOrg = new int[width, height]; float[,] imgY = new float[newWidth, newHeight]; float[,] imgCg = new float[newWidth, newHeight]; float[,] imgCo = new float[newWidth, newHeight]; int[,] imgIY = new int[newWidth, newHeight]; int[,] imgICg = new int[newWidth, newHeight]; int[,] imgICo = new int[newWidth, newHeight]; for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { imgIY[x, y] = br.ReadInt32(); imgICg[x, y] = br.ReadInt32(); imgICo[x, y] = br.ReadInt32(); } } br.Close(); ArrayHelper2D.ConvertIntToFloat(ref imgIY, ref imgY, newWidth, newHeight); ArrayHelper2D.ConvertIntToFloat(ref imgICg, ref imgCg, newWidth, newHeight); ArrayHelper2D.ConvertIntToFloat(ref imgICo, ref imgCo, newWidth, newHeight); Biorthogonal53Wavelet2D wavelet = new Biorthogonal53Wavelet2D(newWidth, newHeight, 8, 8, true); //revert simple quantification float quant = (float)((100.0f - quality) + 1.0f); for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { imgY[x, y] *= quant; imgCg[x, y] *= quant; imgCo[x, y] *= quant; } } wavelet.BackTransformIsotropic2D(ref imgY); wavelet.BackTransformIsotropic2D(ref imgCg); wavelet.BackTransformIsotropic2D(ref imgCo); YCbCrColor.YCbCrArraysToRGBArray(ref imgY, ref imgCg, ref imgCo, width, height, ref imgOrg); return(imgOrg); //return RGBColor.CreateBitmapFromRGBArray(ref imgOrg, width, height); }