<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Форум компьютерной помощи &mdash; Как в XML документ добавить изображение]]></title>
	<link rel="self" href="https://itpmr.ru/extern.php?action=feed&amp;tid=791&amp;type=atom" />
	<updated>2013-07-25T12:23:24Z</updated>
	<generator>PunBB</generator>
	<id>https://itpmr.ru/viewtopic.php?id=791</id>
		<entry>
			<title type="html"><![CDATA[Re: Как в XML документ добавить изображение]]></title>
			<link rel="alternate" href="https://itpmr.ru/viewtopic.php?pid=123893#p123893" />
			<content type="html"><![CDATA[]]></content>
			<author>
				<name><![CDATA[admin]]></name>
				<uri>https://itpmr.ru/profile.php?id=2</uri>
			</author>
			<updated>2013-07-25T12:23:24Z</updated>
			<id>https://itpmr.ru/viewtopic.php?pid=123893#p123893</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Как в XML документ добавить изображение]]></title>
			<link rel="alternate" href="https://itpmr.ru/viewtopic.php?pid=123892#p123892" />
			<content type="html"><![CDATA[<p>Полученные цвет и координаты вставляем в стили XML, как показано выше было. Может кому понадобится))))</p>]]></content>
			<author>
				<name><![CDATA[kalash]]></name>
				<uri>https://itpmr.ru/profile.php?id=2235</uri>
			</author>
			<updated>2013-07-19T08:55:28Z</updated>
			<id>https://itpmr.ru/viewtopic.php?pid=123892#p123892</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Как в XML документ добавить изображение]]></title>
			<link rel="alternate" href="https://itpmr.ru/viewtopic.php?pid=123891#p123891" />
			<content type="html"><![CDATA[<p>На днях понадобилось в xml установить вложенную картинку. Оказалось довольно все просто, необходимо в стилях xml указать цвет и расположение попиксельно всего изображения.<br />img {&nbsp; &nbsp;display: table;<br />&nbsp; &nbsp; width: 1px;<br />&nbsp; &nbsp; height: 1px;<br />&nbsp; &nbsp; background: transparent;<br />&nbsp; &nbsp; box-shadow:0px 0px #FFFFFF, 0px 1px #FFFFFF, 0px 2px #FFFFFF,.............}</p><p>для получения цвета и расположения каждого пикселя была написана простенькая программка:</p><p>using System;<br />using System.Collections.Generic;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Linq;<br />using System.Text;<br />using System.Windows.Forms;</p><p>namespace Format_Img<br />{<br />&nbsp; &nbsp; public partial class Form1 : Form<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; public Form1()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitializeComponent();<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Bitmap bmp;<br />&nbsp; &nbsp; &nbsp; &nbsp; //подключить картинку<br />&nbsp; &nbsp; &nbsp; &nbsp; private void button1_Click(object sender, EventArgs e)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (openFileDialog1.ShowDialog()==DialogResult.OK)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pictureBox1.ImageLocation = openFileDialog1.FileName;//загружаем цветную картинку<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bmp = new Bitmap(openFileDialog1.FileName);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; px_cvet.Text = vivod(bmp);//вывод координаты и цвет пикселя<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B_W();//делаем черно-белую картинку&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; //вывести результат<br />&nbsp; &nbsp; &nbsp; &nbsp; private string vivod(Bitmap bmp2)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string str = &quot;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int x = 0; x &lt; bmp2.Width; x++)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int y = 0; y &lt; bmp2.Height; y++)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string hex=RGB2Hex(bmp2.GetPixel(x, y).R.ToString(), bmp2.GetPixel(x, y).G.ToString(), bmp2.GetPixel(x, y).B.ToString());<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (hex != &quot;#FFFFFF&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str += x.ToString() + &quot;px &quot; + y.ToString() + &quot;px &quot; + hex + &quot;, &quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str = str.Substring(0, str.Length - 2) + &quot;;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return str;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; //перевод RGB<br />&nbsp; &nbsp; &nbsp; &nbsp; public string RGB2Hex(string R, string G, string B)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string Color1 = &quot;#&quot;;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R = Convert.ToString(Convert.ToByte(R));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; G = Convert.ToString(Convert.ToByte(G));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B = Convert.ToString(Convert.ToByte(B));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Color1 += Convert.ToInt32(R).ToString(&quot;X2&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Color1 += Convert.ToInt32(G).ToString(&quot;X2&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Color1 += Convert.ToInt32(B).ToString(&quot;X2&quot;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Color1;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; //черно белая<br />&nbsp; &nbsp; &nbsp; &nbsp; private void B_W()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // делаем пустую картинку того же размера<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap bmp3 = new Bitmap(bmp.Width, bmp.Height, bmp.PixelFormat);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int y = 0; y &lt; bmp.Height; ++y)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int x = 0; x &lt; bmp.Width; ++x)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Color c = bmp.GetPixel(x, y);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte rgb = (byte)(0.3 * c.R + 0.59 * c.G + 0.11 * c.B);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bmp3.SetPixel(x, y, Color.FromArgb(c.A, rgb, rgb, rgb));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pictureBox2.Image = bmp3;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; px_bw.Text = vivod(bmp3);//вывод координаты и цвет пикселя<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}</p>]]></content>
			<author>
				<name><![CDATA[kalash]]></name>
				<uri>https://itpmr.ru/profile.php?id=2235</uri>
			</author>
			<updated>2013-07-19T08:53:02Z</updated>
			<id>https://itpmr.ru/viewtopic.php?pid=123891#p123891</id>
		</entry>
</feed>
