public unsafe void Extract(out IntPtr phBmpThumbnail) { System.IO.StreamWriter logfile = new System.IO.StreamWriter("C:\thumbs-log.txt", true); logfile.WriteLine("Called Extract"); logfile.Close(); System.Drawing.Bitmap designBitmap = designFile.designToBitmap(3, false, 0, 1.0f); IntPtr hBmp = designBitmap.GetHbitmap(); phBmpThumbnail = new IntPtr(); // Assuming you already have hBmp as the handle to your Bitmap object... if (IntPtr.Size == 4) { int *pBuffer = (int *)phBmpThumbnail.ToPointer(); * pBuffer = hBmp.ToInt32(); // IMO, casting back to (void*) is not necessary. // I guess just for formality, that pBuffer points // to an object, not an int. :) phBmpThumbnail = new IntPtr((void *)pBuffer); } else // 8-bytes, or 64-bit { long *pBuffer = (long *)phBmpThumbnail.ToPointer(); * pBuffer = hBmp.ToInt64(); phBmpThumbnail = new IntPtr((void *)pBuffer); } }
static void generateImage(string filename) { try { PesFile.PesFile design = new PesFile.PesFile(filename); Bitmap DrawArea = design.designToBitmap(5.0f, false, 0.0f, 1.0f); Bitmap temp = new Bitmap(DrawArea.Width, DrawArea.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics tempGraph = Graphics.FromImage(temp)) { tempGraph.FillRectangle(Brushes.White, 0, 0, temp.Width, temp.Height); tempGraph.DrawImageUnscaled(DrawArea, 0, 0); tempGraph.Dispose(); temp.Save(System.IO.Path.ChangeExtension(filename, ".png")); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
static void Main(string[] args) { if (args.Length > 0) { try { if (args[0] == "--image" && args.Length > 1) { PesFile.PesFile design = new PesFile.PesFile(args[1]); Bitmap DrawArea = design.designToBitmap(5, false, 0); Bitmap temp = new Bitmap(DrawArea.Width, DrawArea.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics tempGraph = Graphics.FromImage(temp); tempGraph.FillRectangle(Brushes.White, 0, 0, temp.Width, temp.Height); tempGraph.DrawImageUnscaled(DrawArea, 0, 0); tempGraph.Dispose(); temp.Save(System.IO.Path.ChangeExtension(args[1], ".png")); } else { PesFile.PesFile design = new PesFile.PesFile(args[0]); design.saveDebugInfo(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else { Console.WriteLine("Specify input file"); for (int x = 0; x < args.Length; x++) { Console.WriteLine(args[x]); } } }
static void Main(string[] args) { if (args.Length > 0) { try { if (args[0] == "--image" && args.Length > 1) { PesFile.PesFile design = new PesFile.PesFile(args[1]); Bitmap DrawArea = design.designToBitmap(5, false, 0, 100); Bitmap temp = new Bitmap(DrawArea.Width, DrawArea.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics tempGraph = Graphics.FromImage(temp); tempGraph.FillRectangle(Brushes.White, 0, 0, temp.Width, temp.Height); tempGraph.DrawImageUnscaled(DrawArea, 0, 0); tempGraph.Dispose(); temp.Save(System.IO.Path.ChangeExtension(args[1], ".png")); } else { PesFile.PesFile design = new PesFile.PesFile(args[0]); design.saveDebugInfo(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else { Console.WriteLine("Specify input file"); for (int x = 0; x < args.Length; x++) { Console.WriteLine(args[x]); } } }
private void updateDesignImage() { if (design == null) { // No design loaded - nothing to update return; } Bitmap tempImage = design.designToBitmap((float)settings.threadThickness, (settings.filterStiches), settings.filterStitchesThreshold, 1.0f); // Rotate image switch (designRotation) { case 90: tempImage.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case 180: tempImage.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 270: tempImage.RotateFlip(RotateFlipType.Rotate270FlipNone); break; } // Scale image if (fitToWindowToolStripMenuItem.Checked) { // Calculate size of image based on available drawing area float windowWidth = panel2.Width - 3; float windowHeight = panel2.Height - 3; // Figure out which dimension is more constrained float widthScale = windowWidth / tempImage.Width; float heightScale = windowHeight / tempImage.Height; if (widthScale < heightScale) { designScale = widthScale; } else { designScale = heightScale; } } int width = (int)(tempImage.Width * designScale); int height = (int)(tempImage.Height * designScale); if (width < 1 || height < 1) { // Image area is too small to update return; } if (width != tempImage.Width || height != tempImage.Height) { // Scale image code from http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp Rectangle destRect = new Rectangle(0, 0, width, height); Bitmap destImage = new Bitmap(width, height); destImage.SetResolution(tempImage.HorizontalResolution, tempImage.VerticalResolution); using (var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.TileFlipXY); graphics.DrawImage(tempImage, destRect, 0, 0, tempImage.Width, tempImage.Height, GraphicsUnit.Pixel, wrapMode); } } // Keep the scaled image and toss the intermediate image tempImage = destImage; } // Add transparency grid if (settings.transparencyGridEnabled) { DrawArea = new Bitmap(tempImage.Width, tempImage.Height); using (Graphics g = Graphics.FromImage(DrawArea)) { Color gridColor = settings.transparencyGridColor; using (Pen gridPen = new Pen(gridColor)) { int gridSize = settings.transparencyGridSize; for (int xStart = 0; (xStart * gridSize) < DrawArea.Width; xStart++) { for (int yStart = 0; (yStart * gridSize) < DrawArea.Height; yStart++) { // Fill even columns in even rows and odd columns in odd rows if ((xStart % 2) == (yStart % 2)) { g.FillRectangle(gridPen.Brush, (xStart * gridSize), (yStart * gridSize), gridSize, gridSize); } } } } g.DrawImage(tempImage, 0, 0); } } else { DrawArea = tempImage; } panel1.Width = DrawArea.Width; panel1.Height = DrawArea.Height; panel1.Invalidate(); panel2LastUpdateSize = panel2.Size; // Update window title this.Text = System.IO.Path.GetFileName(loadedFileName) + " (" + (designScale * 100).ToString("0") + "%) - " + APP_TITLE; }
private void openFile(string filename) { if (!System.IO.File.Exists(filename)) { return; } design = new PesFile.PesFile(filename); if (design.getStatus() == PesFile.statusEnum.Ready) { this.Text = System.IO.Path.GetFileName(filename) + " - " + APP_TITLE; DrawArea = design.designToBitmap((float)settings.threadThickness, (settings.filterStiches), (int)settings.filterStitchesThreshold); panel1.Width = design.GetWidth() + (int)(settings.threadThickness * 2); panel1.Height = design.GetHeight() + (int)(settings.threadThickness * 2); panel1.Invalidate(); if (design.getFormatWarning()) { toolStripStatusLabel1.Text = "The format of this file is not completely supported"; } else if (design.getColorWarning()) { toolStripStatusLabel1.Text = "Colors shown for this design may be inaccurate"; } else { toolStripStatusLabel1.Text = ""; } copyToolStripMenuItem.Enabled = true; saveDebugInfoToolStripMenuItem.Enabled = true; printPreviewToolStripMenuItem.Enabled = true; printToolStripMenuItem.Enabled = true; rotateLeftToolStripMenuItem.Enabled = true; rotateRightToolStripMenuItem.Enabled = true; refreshToolStripMenuItem.Enabled = true; showDebugInfoToolStripMenuItem.Enabled = true; saveAsBitmapToolStripMenuItem.Enabled = true; panel2.Select(); } else { string message = "An error occured while reading the file:" + Environment.NewLine + design.getLastError(); if (design.getStatus() == PesFile.statusEnum.ParseError) { message += Environment.NewLine + "This file is either corrupt or not a valid PES file."; } MessageBox.Show(message); copyToolStripMenuItem.Enabled = false; saveDebugInfoToolStripMenuItem.Enabled = false; printPreviewToolStripMenuItem.Enabled = false; printToolStripMenuItem.Enabled = false; rotateLeftToolStripMenuItem.Enabled = false; rotateRightToolStripMenuItem.Enabled = false; refreshToolStripMenuItem.Enabled = false; showDebugInfoToolStripMenuItem.Enabled = false; saveAsBitmapToolStripMenuItem.Enabled = false; } }