[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 461
  • Last Modified:

Display image

I have created two separate applications on is a setup tool that an admin will use to create all the configuration information for the users application. This configuration information is going to be stored inside an XML file. The user application will then read the XML file and apply all settings with in that XML file.

Part of those setting is displaying map images of a building in thumbnail format. Now I am unsure which way will be the easier of the two ideas I have. My first idea is to have the application read a directory destination from the XML file and display the images in that directory in thumbnail format. Then the user can click on the thumbnail and the image will be displayed in full size in a second window. In the second window the user should be able to zoom and pan the image.

 However the problem with idea one is I also need the icon image to be displayed over top the map images representing specific security device like a locked door, intercom station, video camera, and so on. So I thought the user application could read the image file name from the XML file and display that and it would also have the icon image location stated there as well. Grant I would still have to tell it what directory the image was in but the second idea might be easier since I need the icon image as well.

The XML schema I have is something like this:

<Setup>
<Options>
    <Maps>
      <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory>
      <Map>
        <FileName>Testing image.bmp</FileName>
        <Icons>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>250,175</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>270,175</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>230,175</Location>
          </Icon>
        </Icons>
      </Map>
    </Maps>
  </Options>
</Setup>

The code I am using for my two forms is attached below.


I want to know which way is better to read my information from the XML and how to go about doing it?
0
seahna
Asked:
seahna
  • 3
  • 2
2 Solutions
 
Miguel OzSoftware EngineerCommented:

Please provide more information:
Can you post your form code?
Also provide some guidance regarding program usage? (how many doors, readers/door, icons, maps)
Is it going to be only one GUI and one setup program in the whole site?

I do not think that your xml as is will solve your problems.
For starters, you need:
An icon list which contains what kind of icon is and information about where to load it.
A map list that contains all maps, in here you can specify the icon id as well as the visual display properties.
Note: This can be separate xml files or included as a node, but if the number of points is huge you file as well will be
If you need to read Xml just use XmlDocument and xpath notation:
http://www.codeproject.com/KB/cpp/myXPath.aspx
http://www.c-sharpcorner.com/UploadFile/mahesh/ReadWriteXMLTutMellli2111282005041517AM/ReadWriteXMLTutMellli21.aspx

I did work for an Australian company that did this sort of work (SCADA security application that integrates video, intercom and access control) and we use a database because of the number of points, reference integrity and concurrency issues due to multiple GUIs accessing the setup data.
0
 
seahnaAuthor Commented:
Sorry didn't realize that my code didn't attach.
Form 1
-------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Security.Principal;
using System.Xml;

namespace AV4._1_ClientTool.Dialogs1.View
{
    public partial class Maps : Form
    {
        public Maps()
        {
            InitializeComponent();
        }

        //form global variables
        private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"]; 
        ImageList thumbs = new ImageList();
        Size ThumbSize = new Size(72, 72); //64,64
        PictureBox pictureBox1 = new PictureBox();
        Dialogs1.Display.MapDisplay frm = new Dialogs1.Display.MapDisplay();
        public static string targetFileName { get; set; }


        #region Thumbnails

        private void Maps_Load(object sender, EventArgs e)
        {
            XmlDocument myDoc = new XmlDocument();
            myDoc.Load(ConfigFileName);
            string pathX = string.Format("Setup/Options/Maps/MapDirectory");
            XmlNode path = myDoc.SelectSingleNode(pathX);

            thumbs.ImageSize = ThumbSize;
            thumbs.ColorDepth = ColorDepth.Depth32Bit;
            listView1.View = System.Windows.Forms.View.LargeIcon;
            listView1.LargeImageList = thumbs;

;

            pictureBox1.Size = thumbs.ImageSize;
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
            foreach (System.IO.FileInfo fi in di.GetFiles("*.jpg"))
            {
                Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                pictureBox1.Image = Image.FromFile(fi.FullName);
                pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
                thumbs.Images.Add(bmp);
                ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileName(fi.Name), thumbs.Images.Count - 1);
                lvi.Tag = fi.Name;
                listView1.Items.Add(lvi);
            }
            foreach (System.IO.FileInfo fi in di.GetFiles("*.gif"))
            {
                Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                pictureBox1.Image = Image.FromFile(fi.FullName);
                pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
                thumbs.Images.Add(bmp);
                ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileName(fi.Name), thumbs.Images.Count - 1);
                lvi.Tag = fi.Name;
                listView1.Items.Add(lvi);
            }
        }
        #endregion

        #region Full Image Popup
        
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            Point pt = listView1.PointToClient(Cursor.Position);
            ListViewItem lvi = listView1.GetItemAt(pt.X, pt.Y);

            if (lvi != null)
            {
                targetFileName = (string)lvi.Tag;
                frm.Text = lvi.Text;
                frm.Show();
            }
        }

        #endregion

    }
}
-------------------------------------------------------------------
Form 2
-------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Security.Principal;
using System.Xml;


namespace AV4._1_ClientTool.Dialogs1.Display
{
    public partial class MapDisplay : Form
    {
        private double ZOOMFACTOR = 1.25;	// = 25% smaller or larger
        private int MINMAX = 5;		// 5 times bigger or smaller than the ctrl

        public MapDisplay()
        {
            InitializeComponent();

            this.pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

            if (!string.IsNullOrEmpty(AV4._1_ClientTool.Dialogs1.View.Maps.targetFileName))
            {
                ShowFile(AV4._1_ClientTool.Dialogs1.View.Maps.targetFileName);
            }
        }

        public void ShowFile(string targetFileName)
        {
            pictureBox1.Controls.Clear();
            foreach (var item in BusinessTier.IconFactory.ImageSet)
            {
                if (item.Image != targetFileName) continue;

                pictureBox1.Image = Image.FromFile(string.Format(@"{0}\{1}", item.Path, item.Image));
                foreach (var icon in item.Icons)
                {
                    var tempIcon = Image.FromFile(icon.File);
                    var tempPicturebox = new PictureBox
                    {
                        Image = tempIcon,
                        Location = new Point(icon.CoordinateX, icon.CoordinateY),
                        Size = new Size(tempIcon.Width, tempIcon.Height),
                    };
                    pictureBox1.Controls.Add(tempPicturebox);

                }
                break;
            }
        }

        #region Zooming Methods
        /// <summary>
        /// Make the PictureBox dimensions larger to effect the Zoom.
        /// </summary>
        /// <remarks>Maximum 5 times bigger</remarks>
        private void ZoomIn()
        {
            if ((pictureBox1.Width < (MINMAX * panel1.Width)) &&
                (pictureBox1.Height < (MINMAX * panel1.Height)))
            {
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * ZOOMFACTOR);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }

        /// <summary>
        /// Make the PictureBox dimensions smaller to effect the Zoom.
        /// </summary>
        /// <remarks>Minimum 5 times smaller</remarks>
        private void ZoomOut()
        {
            if ((pictureBox1.Width > (panel1.Width / MINMAX)) &&
                (pictureBox1.Height > (panel1.Height / MINMAX)))
            {
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width / ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height / ZOOMFACTOR);
            }
        }

        #endregion

        #region Mouse Events
        private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta < 0)
            {
                ZoomOut();
            }
            else
            {
                ZoomIn();
            }
        }
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            if (pictureBox1.Focused == false)
            {
                pictureBox1.Focus();
            }
        }
        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.panel1.Focus(); // give the form focus instead
        }
        #endregion

        #region Button Events
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ZoomIn();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ZoomOut();
        }
        #endregion
    }
}

Open in new window

0
 
seahnaAuthor Commented:
The program usage is for security. The number of icon kind of depends on the companies security decives they have installed. There are two application the admin one that controls the setup of the other application.
0
 
Miguel OzSoftware EngineerCommented:
Number of devices is important because that will decide your strategy regarding data storage and scalability.
For small site (<100+  devices) your approach seems OK, just keep the icons as a separate Icon list independent of your user interface so that you load it once and use anywhere in your program.
I will put the zoom factor as a setup data as well.
My previous post on using xmldocument and xpath is OK.
Also you may want to use Serialization, if you decide to split your setup file.
http://www.codeproject.com/KB/XML/xml_serializationasp.aspx
Example: Serialize the icon information, so that you can load it form file.
0
 
seahnaAuthor Commented:
Ok thank you very muchfor you help I finally got it figured out and you did provide me some food for thought on how to do thing. I will keep what you say in mind as I move forward.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now