Beispiel #1
0
		public void Image(Image i, Row r, string mimeType, Stream ioin)
		{
			string relativeName;
			string suffix;

			switch (mimeType)
			{
				case "image/bmp":
					suffix = "bmp";
					break;
				case "image/jpeg":
					suffix = "jpeg";
					break;
				case "image/gif":
					suffix = "gif";
					break;
				case "image/png":
				case "image/x-png":
					suffix = "png";
					break;
				default:
					suffix = "unk";
					break;
			}
			Stream io = _sg.GetIOStream(out relativeName, suffix);
			try
			{   
				if (ioin.CanSeek)		// ioin.Length requires Seek support
				{
					byte[] ba = new byte[ioin.Length];
					ioin.Read(ba, 0, ba.Length);
					io.Write(ba, 0, ba.Length);
				}
				else
				{
					byte[] ba = new byte[1000];		// read a 1000 bytes at a time
					while (true)
					{
						int length = ioin.Read(ba, 0, ba.Length);
						if (length <= 0)
							break;
						io.Write(ba, 0, length);
					}
				}
			}
			finally
			{
				io.Flush();
				io.Close();
			}

			relativeName = FixupRelativeName(relativeName);

			// Create syntax in a string buffer
			StringWriter sw = new StringWriter();

			string bookmark = i.BookmarkValue(this.r, r);
			if (bookmark != null)
				sw.WriteLine("<div id=\"{0}\">", bookmark);		// we're using for css style

			string cssName = CssAdd(i.Style, i, null);	// get the style name for this item

			sw.Write("<img src=\"{0}\" class='{1}'", relativeName, cssName);

			string tooltip = i.ToolTipValue(this.r, r);
			if (tooltip != null)
				sw.Write(" alt=\"{0}\"", tooltip);
            int h = i.Height == null? -1: i.Height.PixelsY;
            int w = i.Width == null ? -1 : i.Width.PixelsX;
            switch (i.Sizing)
            {
                case ImageSizingEnum.AutoSize:
                    break;          // this is right
                case ImageSizingEnum.Clip:
                    break;          // not sure how to clip it    
                case ImageSizingEnum.Fit:
                    if (h > 0)
                        sw.Write(" height=\"{0}\"", h.ToString());
                    if (w > 0)
                        sw.Write(" width=\"{0}\"", w.ToString());
                    break;
                case ImageSizingEnum.FitProportional:
                    break;          // would have to create an image to handle this
            }
            
			sw.Write("/>");

			if (bookmark != null)
				sw.Write("</div>");

			tw.Write(Action(i.Action, r, sw.ToString(), tooltip));
			return;
		}
        public void Image(Image i, Row r, string mimeType, Stream ioin)
        {
            string relativeName;
            string suffix;

            switch (mimeType)
            {
                case "image/bmp":
                    suffix = "bmp";
                    break;
                case "image/jpeg":
                    suffix = "jpeg";
                    break;
                case "image/gif":
                    suffix = "gif";
                    break;
                case "image/png":
                case "image/x-png":
                    suffix = "png";
                    break;
                default:
                    suffix = "unk";
                    break;
            }
            Stream io = _sg.GetIOStream(out relativeName, suffix);
            try
            {
                if (ioin.CanSeek)		// ioin.Length requires Seek support
                {
                    byte[] ba = new byte[ioin.Length];
                    ioin.Read(ba, 0, ba.Length);
                    io.Write(ba, 0, ba.Length);
                }
                else
                {
                    byte[] ba = new byte[1000];		// read a 1000 bytes at a time
                    while (true)
                    {
                        int length = ioin.Read(ba, 0, ba.Length);
                        if (length <= 0)
                            break;
                        io.Write(ba, 0, length);
                    }
                }
            }
            finally
            {
                io.Flush();
                io.Close();
            }
            if (i.ImageSource == ImageSourceEnum.Embedded) // embedded image in html
                relativeName = "data:" + mimeType + ";base64," + i.EmbeddedImageData;
            else
                relativeName = FixupRelativeName(relativeName);

            // Create syntax in a string buffer
            StringWriter sw = new StringWriter();

            string bookmark = i.BookmarkValue(this.r, r);
            if (bookmark != null)
                sw.WriteLine("<div id=\"{0}\">", bookmark);		// we're using for css style

            string cssName = CssAdd(i.Style, i, null);	// get the style name for this item

            sw.Write("<img src=\"{0}\" class='{1}'", relativeName, cssName);

            string tooltip = i.ToolTipValue(this.r, r);
            if (tooltip != null)
                sw.Write(" alt=\"{0}\"", tooltip);
            if (i.Height != null)
                sw.Write(" height=\"{0}\"", i.Height.PixelsY.ToString());
            if (i.Width != null)
                sw.Write(" width=\"{0}\"", i.Width.PixelsX.ToString());
            sw.Write("/>");

            if (bookmark != null)
                sw.Write("</div>");

            tw.Write(Action(i.Action, r, sw.ToString(), tooltip));
            return;
        }