123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- using PaintDotNet.Base.SettingModel;
- namespace PaintDotNet.GeneralAnalysis.Artwork
- {
- public partial class ArtworkUserControl : UserControl
- {
- private ArtworkModel.Item m_artwork;
- private Bitmap m_artBitmap;
- private Bitmap m_targetBitmap;
- private Bitmap m_overlapBitmap;
- public ArtworkUserControl()
- {
- InitializeComponent();
- }
- public virtual void Init()
- {
- }
- public virtual bool ArtChanged { get; set; }
- public virtual bool AuxiliaryLineEnabled { get; set; }
- public virtual bool GridLineEnabled { get; set; }
- public virtual int Transparency { get; set; }
- public virtual int TargetTransparency { get; set; }
- public virtual bool GenerateTargetPoint { get; set; }
- public ArtworkModel.Item Artwork
- {
- set { this.m_artwork = value; }
- get { return this.m_artwork; }
- }
- public Bitmap ArtBitmap
- {
- get
- {
- return this.m_artBitmap;
- }
- set
- {
- this.m_artBitmap = value;
- BitmapArray[0] = this.m_artBitmap;
- CalcOverlapWidthAndHeight();
- Init();
- }
- }
- public Bitmap TargetBitmap
- {
- get
- {
- return this.m_targetBitmap;
- }
- set
- {
- this.m_targetBitmap = value;
- BitmapArray[1] = this.m_targetBitmap;
- CalcOverlapWidthAndHeight();
- Init();
- }
- }
- public Bitmap TargetBitmapClone { get; set; }
- public Bitmap[] BitmapArray { get; } = new Bitmap[2];
- public int OverlapWidth { get; set; }
- public int OverlapHeight { get; set; }
- /// <summary>
- /// 工艺图和目标图拼合后的图片
- /// </summary>
- public Bitmap OverlapBitmap
- {
- get
- {
- return this.m_overlapBitmap;
- }
- set
- {
- this.m_overlapBitmap = value;
- Init();
- }
- }
- /// <summary>
- /// 目标图移动的相对y坐标
- /// </summary>
- public int TargetTop { get; set; } = 0;
- /// <summary>
- /// 目标图移动的相对x坐标
- /// </summary>
- public int TargetLeft { get; set; } = 0;
- private void CalcOverlapWidthAndHeight()
- {
- OverlapWidth = 0;
- OverlapHeight = 0;
- if (ArtBitmap != null)
- {
- OverlapWidth = ArtBitmap.Width;
- OverlapHeight = ArtBitmap.Height;
- }
- if (TargetBitmap != null)
- {
- OverlapWidth = OverlapWidth > TargetBitmap.Width ? OverlapWidth : TargetBitmap.Width;
- OverlapHeight = OverlapHeight > TargetBitmap.Height ? OverlapHeight : TargetBitmap.Height;
- }
- }
- public enum OverlapType
- {
- CENTER = 0, //中间重叠
- TOPLEFT = 1, //左上角
- }
- public Bitmap Overlap(OverlapType type)
- {
- Bitmap[] bitmaps = this.BitmapArray;
- int width = this.OverlapWidth;
- int height = this.OverlapHeight;
- if (width == 0 || height == 0) {
- return null;
- }
- Bitmap bmPhoto = new Bitmap(width, height);
- float x = 0;
- float y = 0;
- //load the Bitmap into a Graphics object
- Graphics grPhoto = Graphics.FromImage(bmPhoto);
- //Set the rendering quality for this Graphics object
- grPhoto.SmoothingMode = SmoothingMode.AntiAlias;//清除锯齿的呈现
- //haix
- for (int i = 0; i < bitmaps.Length; i++)
- {
- Bitmap img = bitmaps[i];
- if(img == null)
- {
- continue;
- }
- if (type == OverlapType.CENTER)
- {
- x = (width - img.Width) / 2.0f;
- y = (height - img.Height) / 2.0f;
- if (i == 1)
- {
- x += TargetLeft;
- y += TargetTop;
- }
- }
-
- grPhoto.DrawImage(img, new PointF(x,y));
- }
- return bmPhoto;
- }
- //定义图像透明度调整函数
- public Bitmap MakeTransparent(Bitmap src, int num)
- {
- return ImageTools.MakeTransparent(src, num);
- }
- }
- }
|