B2024-060-Adding-a-picture-PROMS-crashes

This commit is contained in:
Paul Larsen 2024-08-22 08:19:20 -04:00
parent 7713f0cd63
commit c06744b3bb
2 changed files with 59 additions and 19 deletions

View File

@ -111,7 +111,13 @@ namespace Volian.Controls.Library
get { return tbFSHt.Text; }
set { tbFSHt.Text = value; tbFSHt.Refresh(); _origFigureSizeRatio = float.Parse(value) / float.Parse(tbFSWd.Text); }
}
// B2024-060 needed for resizing image.
public TrackBar TrBarFS
{
get { return trBarFS; }
//set { trBarFS.Value = Convert.ToInt32(value);}
}
#endregion
#region Constructor
public DisplayTags()
@ -417,14 +423,14 @@ namespace Volian.Controls.Library
tbFSWd.Text = wd.ToString();
tbFSHt.Text = ht.ToString();
//trBarFS.Maximum = Math.Max((int)wd2, trBarFS.Maximum);
//if (wd > trBarFS.Maximum) trBarFS.Maximum = wd + 1;
//trBarFS.Minimum = Math.Min(wd, 72);
//trBarFS.Value = (int)wd;
//ImageItem ii = MyEditItem as ImageItem;
//_origFigureSizeWidth = ii.MyPictureBox.Width;
//tbFSWd.Text = ii.MyPictureBox.Width.ToString();
//tbFSHt.Text = ii.MyPictureBox.Height.ToString();
trBarFS.Maximum = Math.Max((int)wd2, trBarFS.Maximum);
if (wd > trBarFS.Maximum) trBarFS.Maximum = wd + 1;
trBarFS.Minimum = Math.Min(wd, 72);
trBarFS.Value = (int)wd;
ImageItem ii = MyEditItem as ImageItem;
_origFigureSizeWidth = ii.MyPictureBox.Width;
tbFSWd.Text = ii.MyPictureBox.Width.ToString();
tbFSHt.Text = ii.MyPictureBox.Height.ToString();
}
else
{
@ -567,8 +573,8 @@ namespace Volian.Controls.Library
trBarFS.Minimum = Math.Min((int)wd, 72);
trBarFS.Value = (int)wd;
_origFigureSizeWidth = ii.MyPictureBox.Width;
//tbFSWd.Text = ii.MyPictureBox.Width.ToString();
//tbFSHt.Text = ii.MyPictureBox.Height.ToString();
tbFSWd.Text = ii.MyPictureBox.Width.ToString();
tbFSHt.Text = ii.MyPictureBox.Height.ToString();
}
private int DoListStepTypes(FormatData fmtdata, StepData topType, string curType)

View File

@ -256,7 +256,8 @@ namespace Volian.Controls.Library
private int _origCfgHt = 0; // keep track if original size was stored in cfg
private int _origCfgWd = 0;
private bool _pastedNew = false; // need this for flagging newly pasted image (may need to clear cfg)
private DisplayTags _displayTags;
private DisplayTags _displayTags = new DisplayTags();
//House myhouse = new House();
#endregion
#region Constructors
@ -316,21 +317,26 @@ namespace Volian.Controls.Library
}
private void SetWidthsAndHeights(System.Drawing.Image img)
{
int wd = img.Width * MyStepPanel.DPI / 72; // converts from screen resolution's DPI to image's points (72/inch)
int ht = img.Height * MyStepPanel.DPI / 72;
int wd = adjustimage(img.Width); // * MyStepPanel.DPI / 72; // converts from screen resolution's DPI to image's points (72/inch)
double ht = (double)wd * aspectratio(img.Width, img.Height);
//int ht = adjustimage(img.Height); // * MyStepPanel.DPI / 72;
if (MyItemInfo.MyContent.MyImage != null) // image is null if creating new.
{
ImageConfig ic = new ImageConfig(MyItemInfo.MyContent.MyImage);
if (!_pastedNew && ic != null && ic.Image_Height != 0)
{
wd = ic.Image_Width * MyStepPanel.DPI / 72;
ht = ic.Image_Height * MyStepPanel.DPI / 72;
wd = adjustimage(ic.Image_Width); // * MyStepPanel.DPI / 72;
ht = (double)wd * aspectratio(img.Width, img.Height);
//ht = wd * (int)aspectratio(img.Width, img.Height);
//ht = adjustimage(ic.Image_Height); // * MyStepPanel.DPI / 72;
}
}
MyPictureBox.Visible = true;
MyPictureBox.Width = wd;
MyPictureBox.Height = ht;
MyPictureBox.Height = (int)ht;
MyPictureBox.SizeMode = PictureBoxSizeMode.Zoom; // as resize matches width/height.
this.Width = MyPictureBox.Width + ImageMargin;
this.Height = MyPictureBox.Height + 10;
@ -340,9 +346,37 @@ namespace Volian.Controls.Library
_displayTags.TbFSwd = wd.ToString();
_displayTags.TbFSht = ht.ToString();
}
}
// B2024-060 adjust pasted image if too large. If the image is too large PROMS crashes.
private int adjustimage(int dim)
{
int dim2 = dim * MyStepPanel.DPI / 72;
if (dim2 > _displayTags.TrBarFS.Maximum)
{
//int y = dim2 - _displayTags.TrBarFS.Maximum;
////int a = y * 72 / MyStepPanel.DPI;
//int a = y * MyStepPanel.DPI / 72;
//dim = dim - a;
//dim2 = dim * MyStepPanel.DPI / 72;
dim2 = _displayTags.TrBarFS.Maximum * 72 / MyStepPanel.DPI;
}
else
{
return dim2;
}
return dim2;
}
// B2024-060 Get aspect ratio to resize pasted image.
private double aspectratio(int w, int h)
{
//double ratio = Math.Max((double)image.width / (double)box.width, (double)image.height / (double)box.height);
//image.width = (int) (image.width / ratio);
//image.height = (int) (image.height / ratio);
double ratio = (double)h / (double)w;
return ratio;
}
// the following gets called for 'NEW' images
private E_ImageSource InsType = E_ImageSource.None;
public ImageItem(ItemInfo itemInfo, StepPanel myStepPanel, EditItem myParentEditItem, ChildRelation myChildRelation, bool expand, EditItem nextEditItem, ImageItem.E_ImageSource insType, DisplayTags displayTags)