Image MakeImage(PictureTag t) { Image img = Image.FromFile(t.Path); int sourceWidth = img.Width; int sourceHeight = img.Height; int width = _width; int height = _height; // Fit height or fit width if (t.FitHeight) { width = img.Width * height / img.Height; // Fit height } else { height = img.Height * width / img.Width; // Fit width } Bitmap bm = new Bitmap(_width, _height); Graphics g = Graphics.FromImage(bm); g.FillRectangle(new SolidBrush(t.Background), new Rectangle(0, 0, _width, _height)); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Rectangle r = new Rectangle((_width - width)/2,(_height - height)/2,width,height); g.DrawImage(img,r); g.Dispose(); return bm; }
internal void InsertPicture (Line line, int pos, RTF.Picture picture) { //LineTag next_tag; LineTag tag; int len; len = 1; // Just a place holder basically line.text.Insert (pos, "I"); PictureTag picture_tag = new PictureTag (line, pos + 1, picture); tag = LineTag.FindTag (line, pos); picture_tag.CopyFormattingFrom (tag); /*next_tag = */tag.Break (pos + 1); picture_tag.Previous = tag; picture_tag.Next = tag.Next; tag.Next = picture_tag; // // Picture tags need to be surrounded by text tags // if (picture_tag.Next == null) { picture_tag.Next = new LineTag (line, pos + 1); picture_tag.Next.CopyFormattingFrom (tag); picture_tag.Next.Previous = picture_tag; } tag = picture_tag.Next; while (tag != null) { tag.Start += len; tag = tag.Next; } line.Grow (len); line.recalc = true; UpdateView (line, pos); }