public int ExeGraphCompare(int[] lXferData, string[] lXferFile, ref string Msg, ref bool Result, int Line) { Bitmap BmpImage; int ret = 0; if (lXferData.Length > 0) { WarnResult(IMGCMPTOKEN, NOPARAMETER, ref Msg, Line); } if (lXferFile.Length < 3) { Result = false; ErrResult(IMGCMPTOKEN, NOPARAMETER, ref Msg, Line); return(SystemInfo.ERROR_CMP_NOPARAM); } SL_Img_Lib CmpImg = new SL_Img_Lib(lXferFile[0]); ret = CmpImg.CompareGrpah(lXferFile[1], ref Msg, ref lCmpInfo); if (ret == SystemInfo.ERROR_CMP_FILENOTEXIST) { WarnResult(IMGCMPTOKEN, FILENOTEXIST, ref Msg, Line); } else if (ret == SystemInfo.ERROR_CMP_ERROR) { CmpImg.SaveTxtResult(lXferFile[2], ref lCmpInfo, true); BmpImage = CmpImg.getResultBmp(); BmpImage.Save(lXferFile[2]); WarnResult(IMGCMPTOKEN, BMPCMPNOTMATCH, ref Msg, Line); } else { WarnResult(IMGCMPTOKEN, BMPCMPMATCH, ref Msg, Line); } return(Chip.ERROR_RESULT_OK); }
private static int CheckPhoto(BmpImage image) { bool isGray = true; // bitCount == 8 if (image.Data.ColorMode == BitmapColorMode.TwoFiftySixColors) { for (int i = 0, len = image.Palette.Length; i < len; i++) { if (image.Palette[i].Red != image.Palette[i].Green) { isGray = false; } } if (isGray) { return(1); } } //bitCount == 32 || bitCount == 24 else if (image.Data.ColorMode == BitmapColorMode.TrueColor || image.Data.ColorMode == BitmapColorMode.RGBA) { return(2); } else { return(0); } return(0); }
public GrayToBinaryConverter(BmpImage data) : base(data) { if (data.Data.ColorMode != BitmapColorMode.TwoFiftySixColors) { throw new NotThisColorModeException("Gray ToBinary Converters are only for Gray images"); } }
public BmpImage predicate() { var oldData = this.image.Data; byte[] newData = new byte[oldData.GetRealSize()]; int width = oldData.Width; int height = oldData.Height; Position pos = new Position(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { //TODO: to calculate every predicated pixel value pos.x = i; pos.y = j; newData[i * width + j] = (byte)((oldData.Data[i * width + j] - PredictSinglePixel(pos)) / 2 + 128); } } BmpImage pImage = BmpImageAllocator.NewGrayScaleImage(width, height, newData); ImageFile.SaveBmpImage(pImage, savedFilePath + "//" + fileName + ".bmp"); HuffmanCompression huffCompress = new HuffmanCompression(newData); huffCompress.Compress(savedFilePath + "//" + fileName + ".dat"); return(pImage); }
public static void Run() { // ExStart:CreateThumbnailsFromPSDFiles // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD in an instance of PsdImage using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd")) { // Iterate over the PSD resources foreach (var resource in image.ImageResources) { // Check if the resource is of thumbnail type if (resource is ThumbnailResource) { // Retrieve the ThumbnailResource and Check the format of the ThumbnailResource var thumbnail = (ThumbnailResource)resource; if (thumbnail.Format == ThumbnailFormat.KJpegRgb) { // Create a new BmpImage by specifying the width and height, Store the pixels of thumbnail on to the newly created BmpImage and save image BmpImage thumnailImage = new BmpImage(thumbnail.Width, thumbnail.Height); thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData); thumnailImage.Save(dataDir + "CreateThumbnailsFromPSDFiles_out.bmp"); } } } } // ExEnd:CreateThumbnailsFromPSDFiles }
public static void Run() { //ExStart:ExportImageToPSD // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Create a new image from scratch. using (BmpImage bmpImage = new BmpImage(300, 300)) { // Fill image data. Graphics graphics = new Graphics(bmpImage); graphics.Clear(Color.White); var pen = new Pen(Color.Brown); graphics.DrawRectangle(pen, bmpImage.Bounds); // Create an instance of PsdOptions, Set it's various properties Save image to disk in PSD format PsdOptions psdOptions = new PsdOptions(); psdOptions.ColorMode = ColorModes.Rgb; psdOptions.CompressionMethod = CompressionMethod.Raw; psdOptions.Version = 4; bmpImage.Save(dataDir + "ExportImageToPSD_output.psd", psdOptions); } //ExEnd:ExportImageToPSD }
static void Extract(string filename) { string fname = System.IO.Path.GetFileNameWithoutExtension(filename); Binary file = new Binary(filename); long sectors = file.Length / SECTOR_SIZE; Console.WriteLine("{0} BYTES, {1} SECTORS", file.Length, sectors); A1R5G5B5Image screen = new A1R5G5B5Image(640, 480); BmpImage image = new BmpImage(640, 480); Binary sector; for (int i = 0; i < sectors; i++) { Console.WriteLine("Extracting SECTOR {0}", i); sector = new Binary(file[SECTOR_SIZE * i, SECTOR_SIZE]); screen.Read(sector); image.SetPixels(screen.Pixels); image.Save(string.Format(fname + "_{0:000}.bmp", i)); } Console.WriteLine("Done!"); }
private BmpImage Inverse1BitBitmap() { BmpImage result = new BmpImage() { Palette = new BitmapPaletteEntry[2] }; result.Palette[0] = new BitmapPaletteEntry((byte)0, (byte)0, (byte)0, 0); result.Palette[1] = new BitmapPaletteEntry((byte)255, (byte)255, (byte)255, 0); result.Data = new BitmapData { ColorMode = BitmapColorMode.MonoChrome, Width = Image.Data.Width, Height = Image.Data.Height }; result.Data.Data = new byte[result.Data.GetRealSize()]; for (int i = 0; i < Image.Data.Width; i++) { for (int j = 0; j < Image.Data.Height; j++) { if (UniformQuantizingData[i, j] == 0) { result.Data.Set1BitDataAt(i, j, false); } else { result.Data.Set1BitDataAt(i, j, true); } } } return(result); }
// no CR means IGS Uniform Quantizing (CR = 2) public UniformQuantizing(BmpImage image) { QuantizingInterval = 16.0; TotalIntervals = 16; Image = image; IGSUniformQuantizaing(); }
public static BmpImage NewGrayScaleImage(int width, int height, byte[] data = null) { BmpImage result = new BmpImage() { Palette = new BitmapPaletteEntry[256] }; for (int i = 0; i < 256; i++) { result.Palette[i] = new BitmapPaletteEntry((byte)i, (byte)i, (byte)i, 0); } result.Data = new BitmapData { ColorMode = BitmapColorMode.TwoFiftySixColors, Width = width, Height = height }; if (data == null) { result.Data.Data = new byte[result.Data.GetRealSize()]; } else { result.Data.Data = data; } return(result); }
private static void ModuleTwo(BmpImage image) { /* * 直方图均衡: * 1.灰度图像: * 进行直方图均衡,将均衡结果在存储至某一目录 * 2.真彩图像: * 1.对其进行彩色变换(RGB->HSV): * 2.对亮度分量做直方图均衡 * 3.做彩色反变换得到均衡结果,存储至某一目录 */ int photoFormat = CheckPhoto(image); if (photoFormat == 1) { System.Console.Write("\n检测到图片为灰度图像"); System.Console.WriteLine("进行直方图均衡....."); var ge = new GrayEqualization(image); image = ge.Equalization().Image; System.Console.WriteLine("完成直方图均衡!"); System.Console.WriteLine("----原始图像直方图----"); DrawHistogram(image.Data.Width * image.Data.Height, ge.hist); var sv = new int[256]; for (int i = 0; i < image.Data.Width; i++) { for (int k = 0; k < image.Data.Height; k++) { sv[image.Data.Get8BitDataAt(i, k)]++; } } System.Console.WriteLine("----均衡图像直方图----"); DrawHistogram(image.Data.Width * image.Data.Height, sv); } else if (photoFormat == 2) { System.Console.Write("\n检测到图片为彩色图像"); System.Console.WriteLine("进行直方图均衡(彩色变换为RGB->HSV)....."); var ge = new ColorEqualization(image); image = ge.Equalization().Image; System.Console.WriteLine("完成直方图均衡!"); System.Console.WriteLine("----原始图像直方图----"); DrawHistogram(image.Data.Width * image.Data.Height, ge.histV); var sv = new int[256]; for (int i = 0; i < image.Data.Width; i++) { for (int k = 0; k < image.Data.Height; k++) { var rgb = image.Data.GetRGBDataAt(i, k); sv[(rgb.R + rgb.G + rgb.B) / 3]++; } } System.Console.WriteLine("----均衡图像直方图----"); DrawHistogram(image.Data.Width * image.Data.Height, sv); } else { System.Console.Write("\n图片形式不支持模块转换哟~\n"); } }
public void TestIGSUniformQuantizing() { var image = ImageFile.LoadBmpImage("..\\..\\..\\TestImages\\lenna_gray.bmp"); UniformQuantizing igs = new UniformQuantizing(image); BmpImage igsImage = igs.InverseUniformQuantizaing(); ImageFile.SaveBmpImage(igsImage, "..\\..\\..\\TestImages\\lenna_igs_modified.bmp"); Assert.Equal(16, igs.TotalIntervals); }
public void TestUniformQuantizingCompress8() { var image = ImageFile.LoadBmpImage("..\\..\\..\\TestImages\\lenna_gray.bmp"); UniformQuantizing uq = new UniformQuantizing(image, 8.0); BmpImage uqImage = uq.InverseUniformQuantizaing(); ImageFile.SaveBmpImage(uqImage, "..\\..\\..\\TestImages\\lenna_uq8_modified.bmp"); Assert.Equal(2, uq.TotalIntervals); }
public BmpImage GetDCTImage() { if (Image.Data.ColorMode != BitmapColorMode.TwoFiftySixColors) { throw new NotThisColorModeException(); } BmpImage result = BmpImageAllocator.NewGrayScaleImage(Image.Data.Width, Image.Data.Height); DCTData = new double[Image.Data.Width, Image.Data.Height]; for (int i = 0; i < Image.Data.Width / BlockSize; i++) { for (int k = 0; k < Image.Data.Height / BlockSize; k++) { int[,] block = new int[BlockSize, BlockSize]; for (int m = 0; m < BlockSize; m++) { for (int n = 0; n < BlockSize; n++) { block[m, n] = Image.Data.Get8BitDataAt(BlockSize * i + m, BlockSize * k + n); } } double[,] dctBlock = GenerateDCTBlock(block); double min = 99999999; double max = -99999999; for (int m = 0; m < BlockSize; m++) { for (int n = 0; n < BlockSize; n++) { if (dctBlock[m, n] > max) { max = dctBlock[m, n]; } if (dctBlock[m, n] < min) { min = dctBlock[m, n]; } } } for (int m = 0; m < BlockSize; m++) { for (int n = 0; n < BlockSize; n++) { result.Data.Set8BitDataAt( BlockSize * i + m, BlockSize * k + n, (byte)((dctBlock[m, n] - min) / (max - min) * 255)); DCTData[BlockSize * i + m, BlockSize *k + n] = dctBlock[m, n]; } } } } return(result); }
public UniformQuantizing(BmpImage image, double CompressRatio) { double intendingBit = 8.0 / CompressRatio; double intendingTotalIntervals = Math.Pow(2, intendingBit); QuantizingInterval = 256.0 / intendingTotalIntervals; TotalIntervals = (int)Math.Ceiling(intendingTotalIntervals); Image = image; UniformQuantizingCompress(); }
public static void SaveBmpImage(BmpImage image, string filePath) { BmpImageGenerator generator = new BmpImageGenerator(image); generator.Generate(); var fs = File.OpenWrite(filePath); fs.Write(generator.ImageBytes, 0, generator.ImageBytes.Length); fs.Close(); }
public void TestGetDCTReverseImageWithCompression() { var image = ImageFile.LoadBmpImage("..\\..\\..\\TestImages\\lenna_gray.bmp"); var dct = new DCTCompression(image, 15); BmpImage dctImage = dct.GetDCTImage(); ImageFile.SaveBmpImage(dctImage, "..\\..\\..\\TestImages\\lenna_dct_comp_modified.bmp"); BmpImage reverseImage = dct.GetDCTReverseImage(8.0); ImageFile.SaveBmpImage(reverseImage, "..\\..\\..\\TestImages\\lenna_dct_reverse_comp_modified.bmp"); }
private void BuildScreen() { var screenLeft = _monitor.Bounds.Left; var screenTop = _monitor.Bounds.Top; using (var g = Graphics.FromImage(BmpImage)) g.CopyFromScreen(screenLeft, screenTop, 0, 0, BmpImage.Size); using (var stream = new MemoryStream()) { BmpImage.Save(stream, ImageFormat.Png); _pictureBoxContainer.Image = BmpImage; } }
public BmpImage GetDCTReverseImage(double compressRatio) { if (Image.Data.ColorMode != BitmapColorMode.TwoFiftySixColors) { throw new NotThisColorModeException(); } if (DCTData == null) { throw new UnauthorizedAccessException(); } if (compressRatio < 1.0) { throw new ArgumentOutOfRangeException(); } BmpImage result = BmpImageAllocator.NewGrayScaleImage(Image.Data.Width, Image.Data.Height); for (int i = 0; i < Image.Data.Width / BlockSize; i++) { for (int k = 0; k < Image.Data.Height / BlockSize; k++) { double[,] block = new double[BlockSize, BlockSize]; for (int m = 0; m < BlockSize; m++) { for (int n = 0; n < BlockSize; n++) { if ((m + n > BlockSize * BlockSize / (compressRatio * compressRatio))) { block[m, n] = 0; } else { block[m, n] = DCTData[BlockSize * i + m, BlockSize *k + n]; } } } int[,] dctReverseBlock = GenerateDCTReverseBlock(block); for (int m = 0; m < BlockSize; m++) { for (int n = 0; n < BlockSize; n++) { result.Data.Set8BitDataAt( BlockSize * i + m, BlockSize * k + n, (byte)dctReverseBlock[m, n]); } } } } return(result); }
public void testPredict() { float[] cocs = { 0.5f, 0.5f }; string savedFilePath = "..\\..\\..\\TestImages\\"; string fileName = "lenna_gray_predicated"; LinearPredictor lp = new LinearPredictor(image, savedFilePath, fileName, cocs); BmpImage pImage = lp.predicate(); Assert.Equal(pImage.Data.Width, image.Data.Width); Assert.Equal(pImage.Data.Height, image.Data.Height); Assert.Equal(BitmapColorMode.TwoFiftySixColors, pImage.Data.ColorMode); }
public static void Run() { //ExStart:BMPToPDF string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (BmpImage image = (BmpImage)Image.Load(dataDir)) { Aspose.Imaging.ImageOptions.PdfOptions exportOptions = new PdfOptions(); exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo(); image.Save(dataDir, exportOptions); } }
private BmpImage Inverse8BitsBitmap() { BmpImage result = NewGrayScaleImage(); for (int i = 0; i < Image.Data.Width; i++) { for (int j = 0; j < Image.Data.Height; j++) { result.Data.Set8BitDataAt(i, j, (byte)((UniformQuantizingData[i, j] + 0.5) * QuantizingInterval)); } } return(result); }
public static void Run() { Console.WriteLine("Running example BMPToPDF"); string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (BmpImage image = (BmpImage)Image.Load(System.IO.Path.Combine(dataDir, "sample.bmp"))) { Aspose.Imaging.ImageOptions.PdfOptions exportOptions = new PdfOptions(); exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo(); image.Save(System.IO.Path.Combine(dataDir, "sample_out.pdf"), exportOptions); } Console.WriteLine("Finished example BMPToPDF"); }
public SingleThresholdConverter(BmpImage data, int threshold) : base(data) { if (threshold < 0 || threshold > 255) { throw new ArgumentOutOfRangeException(); } else if (threshold == 0) { Threshold = 128; } else { Threshold = threshold; } }
static void Run() { var pngImage = new PngImage(File.ReadAllBytes("d:\\WImageTest\\test1.png")); var bmpImage = new BmpImage(pngImage.Width, pngImage.Height, BPP.ThirtyTwo); //pngImage.t(bmpImage.Data); //bmpImage.SaveToFile("output.bmp"); //var ddsTexture = new DdsTexture(File.ReadAllBytes("../Textures/Mob.dds")); //ddsTexture.SaveToFile("Mod.dds"); //var ddsTextureCompressed = new DdsTexture(File.ReadAllBytes("../Textures/Mob_dx3.dds")); //ddsTextureCompressed.SaveToFile("Mob_dx3.dds"); }
public BmpImageGenerator(BmpImage image) { this.image = image; int paletteBitCount = 0; if (image.Data.ColorMode == BitmapColorMode.MonoChrome) { paletteBitCount = 2 * 4; } else if (image.Data.ColorMode == BitmapColorMode.TwoFiftySixColors) { paletteBitCount = 256 * 4; } offBits = 14 + 40 + paletteBitCount; }
/* * user can ignore the collections of correalations, it will be set first order */ public LinearPredictor(BmpImage image, string savedFilePath, string fileName, float[] cocs = null) { this.image = image; if (cocs != null) { this.cocs = cocs; } else { this.cocs = new float[] { 1 } }; this.k = this.cocs.Length; this.savedFilePath = savedFilePath; this.fileName = fileName; }
static void Main(string[] args) { string[] files = Directory.GetFiles(".", "*.bmp"); BmpImage inImage; TgaImage outImage; foreach (string file in files) { Console.WriteLine("Converting {0}",file); inImage = new BmpImage(file); outImage = TgaImage.FromBMP(inImage); outImage.Save(file + ".TGA"); } Console.WriteLine("Done!"); }
public void TakeScreenShot(string directory, string fileName) { //Console.WriteLine("Create screenshot"); //Code is taken from the firmware code and simply returns a blank LCD int Width = 178; int Height = 128; BmpImage screenshotImage = new BmpImage(24 * 8, (uint)Height, ColorDepth.TrueColor); RGB startColor = new RGB(188, 191, 161); RGB endColor = new RGB(219, 225, 206); screenshotImage.Clear(); float redActual = (float)endColor.Red; float greenActual = (float)endColor.Green; float blueActual = (float)endColor.Blue; int bytesPrLine = ((Width + 31) / 32) * 4; float redGradientStep = (float)(endColor.Red - startColor.Red) / Height; float greenGradientStep = (float)(endColor.Green - startColor.Green) / Height; float blueGradientStep = (float)(endColor.Blue - startColor.Blue) / Height; RGB color = new RGB(); for (int y = Height - 1; y >= 0; y--) { for (int x = 0; x < bytesPrLine * 8; x++) { color.Red = (byte)redActual; color.Green = (byte)greenActual; color.Blue = (byte)blueActual; screenshotImage.AppendRGB(color); } redActual -= redGradientStep; greenActual -= greenGradientStep; blueActual -= blueGradientStep; } if (fileName == "") { fileName = "ScreenShot" + string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now) + ".bmp"; } if (!fileName.ToLower().EndsWith(".bmp")) { fileName = fileName + ".bmp"; } screenshotImage.WriteToFile(System.IO.Path.Combine(directory, fileName)); }
private static int SavePhoto(BmpImage image) { System.Console.WriteLine("另存为:"); string SavePath = System.Console.ReadLine(); ImageFile.SaveBmpImage(image, @SavePath); System.Console.WriteLine("成功保存文件到:{0}", SavePath); System.Console.WriteLine("显示图片?(1 or 2)"); int display = Convert.ToInt32(System.Console.ReadLine()); if (display == 1) { showPhoto(SavePath); } System.Console.WriteLine("是否继续?(1 or 2)"); int goon = Convert.ToInt32(System.Console.ReadLine()); return(goon); }