private void button1_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog(this) == DialogResult.OK) { this.TargetImage = new Gdi::Bitmap(this.openFileDialog1.FileName); } }
void AllocatePictureImage() { if (this.backImage != null) { if (this.backImage.Width == this.pictureBox1.Width && this.backImage.Height == this.pictureBox1.Height) { return; } this.FreePictureImage(); } int w = this.pictureBox1.Width; if (w <= 0) { w = 1; } int h = this.pictureBox1.Height; if (h <= 0) { h = 1; } this.backImage = new Gdi::Bitmap(w, h); this.foreImage = new Gdi::Bitmap(w, h); this.foreGraphics = Gdi::Graphics.FromImage(this.foreImage); this.foreGraphics.Clear(Gdi::Color.Transparent); this.pictureBox1.BackgroundImage = this.backImage; this.pictureBox1.Image = this.foreImage; this.UpdatePictureImage(); }
private void button3_Click(object sender, EventArgs e) { Gdi::Bitmap deformed = FrameDeformQuadratic.Transform( this.targetImage, this.targetImage.Width, this.targetImage.Height, this.deform.P1, this.deform.P2, this.deform.P3, this.deform.P4, this.deform.Q1, this.deform.Q2, this.deform.Q3, this.deform.Q4); this.TargetImage = deformed; }
private void button2_Click(object sender, EventArgs e) { // クリップボードに格納された画像の取得 try{ IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) { this.TargetImage = (Gdi::Bitmap)data.GetData(DataFormats.Bitmap); } }catch {} }
public BicubicInterpolatedImage(Gdi::Bitmap bmp) { this.bmp = bmp; this.width = bmp.Width; this.height = bmp.Height; Gdi::Rectangle rect = new Gdi::Rectangle(Gdi::Point.Empty, bmp.Size); this.data = bmp.LockBits(rect, Gdi::Imaging.ImageLockMode.ReadOnly, Gdi::Imaging.PixelFormat.Format24bppRgb); this.p0 = (byte *)this.data.Scan0; this.stride = this.data.Stride; }
public static void SaveBitmap(Gdi::Bitmap bmp, string filename) { switch (System.IO.Path.GetExtension(filename).ToLower()) { case ".jpg": case ".jpeg": case ".jfif": bmp.Save(filename, JpegCodec, GetJpegEncParams(90)); break; case ".png": bmp.Save(filename, PngCodec, GetPngEncParams()); break; default: bmp.Save(filename); break; } }
void FreeCache() { #if WIN32PINVOKE if (this.cache_hdc != System.IntPtr.Zero) { DeleteDC(cache_hdc); cache_hdc = System.IntPtr.Zero; } if (this.cache_hbmp != System.IntPtr.Zero) { DeleteObject(cache_hbmp); cache_hbmp = System.IntPtr.Zero; } #endif if (this.cache != null) { this.cache.Dispose(); this.cache = null; } }
public static void WriteToPbm(string input, string output) { Gdi::Bitmap image = new Gdi::Bitmap(input); int w = image.Width; int h = image.Height; Gdi::Imaging.BitmapData data = image.LockBits( new Gdi::Rectangle(Gdi::Point.Empty, image.Size), Gdi::Imaging.ImageLockMode.ReadOnly, Gdi::Imaging.PixelFormat.Format24bppRgb); System.IO.Stream str = System.IO.File.OpenWrite(output); System.IO.StreamWriter sw = new System.IO.StreamWriter(str, System.Text.Encoding.ASCII); sw.WriteLine("P1"); sw.WriteLine("{0} {1}", w, h); unsafe { int i = 0; for (int y = 0; y < h; y++) { RGB *ppx = (RGB *)((byte *)data.Scan0 + data.Stride * y); RGB *ppxM = ppx + w; while (ppx < ppxM) { sw.Write((ppx++)->Intensity() > 0x80?"0":"1"); if (++i % 64 == 0) { sw.WriteLine(); } else { sw.Write(" "); } } } } sw.Close(); str.Close(); image.UnlockBits(data); image.Dispose(); }
/// <summary> /// 描画する背景画像の情報を更新します。 /// </summary> /// <param name="image">描画する背景画像を指定します。</param> /// <param name="scaleX">画像の表示 X 倍率を指定します。</param> /// <param name="scaleY">画像の表示 Y 倍率を指定します。</param> /// <param name="offsetX">画像の表示 X 位置を指定します。</param> /// <param name="offsetY">画像の表示 Y 位置を指定します。</param> /// <param name="displaySize">画面上の表示の大きさを指定します。</param> public void UpdateImage(Gdi::Image image, float scaleX, float scaleY, float offsetX, float offsetY, Gdi::Size displaySize) { if (image == this.original && scaleX == this.scaleX && scaleY == this.scaleY && offsetX == this.offsetX && offsetY == this.offsetY && displaySize == this.displaySize ) { return; } this.original = image; this.scaleX = scaleX; this.scaleY = scaleY; this.offsetX = offsetX; this.offsetY = offsetY; this.displaySize = displaySize; imageArea = new Gdi::RectangleF(offsetX, offsetY, image.Width * scaleX, image.Height * scaleY); // 画面座標での描画領域 Gdi::RectangleF srcRectD = Gdi::RectangleF.Intersect(new Gdi::RectangleF(Gdi::PointF.Empty, displaySize), imageArea); // 画像座標での描画領域 Gdi::RectangleF srcRectI = new Gdi::RectangleF( (srcRectD.X - offsetX) / scaleX, (srcRectD.Y - offsetY) / scaleY, srcRectD.Width / scaleX, srcRectD.Height / scaleY ); srcRectD.X = 0; srcRectD.Y = 0; this.FreeCache(); this.cache = new System.Drawing.Bitmap((int)(srcRectD.Width + .5f), (int)(srcRectD.Height + .5f)); using (Gdi::Graphics g = Gdi::Graphics.FromImage(this.cache)) g.DrawImage(image, srcRectD, srcRectI, Gdi::GraphicsUnit.Pixel); ImageEnlight(this.cache); }
private static void ImageEnlight(Gdi::Bitmap bmp) { // 色を薄くする -> これは GetImage の方に追加するべきではないか Gdi::Imaging.BitmapData data = bmp.LockBits( new Gdi::Rectangle(Gdi::Point.Empty, bmp.Size), Gdi::Imaging.ImageLockMode.ReadWrite, Gdi::Imaging.PixelFormat.Format24bppRgb ); for (int y = 0; y < bmp.Height; y++) { unsafe { byte *p = (byte *)data.Scan0 + data.Stride * y; byte *pM = p + bmp.Width * 3; for (; p < pM; p++) { *p += (byte)((255 - *p) / 3 * 2); //*p/=5; } } } bmp.UnlockBits(data); }
public unsafe static Gdi::Bitmap Transform( Gdi::Bitmap src, int width, int height, Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 q1, Vector2 q2, Vector2 q3, Vector2 q4 ) { Gdi::Bitmap dst = new Gdi::Bitmap(width, height); Gdi::Rectangle dstRect = new Gdi::Rectangle(Gdi::Point.Empty, dst.Size); Gdi::Imaging.BitmapData dstData = dst.LockBits(dstRect, Gdi::Imaging.ImageLockMode.WriteOnly, Gdi::Imaging.PixelFormat.Format32bppRgb); byte *pdst = (byte *)dstData.Scan0; int stride = dstData.Stride; double[] x_st_table1 = new double[width]; double[] x_st_table2 = new double[width]; double[] y_st_table1 = new double[height]; double[] y_st_table2 = new double[height]; new BezierArcMeasure(p1, p2, q1).InitializeTable(x_st_table1); new BezierArcMeasure(p4, p3, q3).InitializeTable(x_st_table2); new BezierArcMeasure(p1, p4, q4).InitializeTable(y_st_table1); new BezierArcMeasure(p2, p3, q2).InitializeTable(y_st_table2); BezierLine p12 = new BezierLine(p1, p2, q1); BezierLine p43 = new BezierLine(p4, p3, q3); BezierLine p14 = new BezierLine(p1, p4, q4); BezierLine p23 = new BezierLine(p2, p3, q2); using (BicubicInterpolatedImage srcImage = new BicubicInterpolatedImage(src)){ for (int ix = 0; ix < width; ix++) { double xt1 = x_st_table1[ix]; double xt2 = x_st_table2[ix]; double dxt = xt2 - xt1; for (int iy = 0; iy < height; iy++) { double yt1 = y_st_table1[iy]; double yt2 = y_st_table2[iy]; double dyt = yt2 - yt1; double xt = (xt1 + yt1 * dxt) / (1 - dxt * dyt); double yt = (yt1 + xt1 * dyt) / (1 - dxt * dyt); // linear interpolation Vector2 pl = (1 - xt1) * (1 - yt1) * p1 + xt1 * (1 - yt2) * p2 + xt2 * yt2 * p3 + (1 - xt2) * yt1 * p4; // bezier interpolation Vector2 pBx = p43.GetPoint(xt2) * yt + p12.GetPoint(xt1) * (1 - yt); Vector2 pBy = p23.GetPoint(yt2) * xt + p14.GetPoint(yt1) * (1 - xt); Vector2 p = pBx + pBy - pl; *(int *)(pdst + 4 * ix + stride * iy) = srcImage.Get(p.x, p.y); } } } dst.UnlockBits(dstData); return(dst); }