EDN Admin
Well-known member
Hi there!<br/>
Got a little problem with some code of mine.
I can assign an image, but the Source-Attribute is not retaining the value.
C#:
<pre class="prettyprint <pre style="font-family:Consolas; font-size:13; color:black; background:white <span style="color:#2b91af MemoryStream memstr;
<span style="color:#2b91af Bitmap toshow;[/code] private void processing(object sender, RoutedEventArgs e)
{
toshow = new Bitmap(thepicture);
Graphics graph = Graphics.FromImage(toshow);
graph.CompositingQuality = CompositingQuality.AssumeLinear;
graph.CompositingMode = CompositingMode.SourceOver;
int i = -1, j = -1,r,g,b,a;
System.Drawing.Color tmp;
while(++i<toshow.Width)
while (++j < toshow.Height)
{
tmp = toshow.GetPixel(i, j);
r = tmp.R - 20;
g = tmp.G - 20;
b = tmp.B - 20;
a = tmp.A;
b = (b < 0) ? 0 : b;
r = (r < 0) ? 0 : r;
g = (g < 0) ? 0 : g;
toshow.SetPixel(i, j, System.Drawing.Color.FromArgb(a, r, g, b));
}
memstr = new MemoryStream();
toshow.Save(memstr, System.Drawing.Imaging.ImageFormat.Bmp);
BitmapImage thisisso****ingstupidofms= new BitmapImage();
thisisso****ingstupidofms.CacheOption = BitmapCacheOption.OnLoad;
thisisso****ingstupidofms.StreamSource = memstr;
#error Source will not retain value.Why???
image_processed.Source = thisisso****ingstupidofms;
} [/code]
XAML<br/>
<pre class="prettyprint <Window x:Class="MutliMediasysteme_Mustererkennung_bsp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="453" Width="845
<Grid>
<Image Height="365" HorizontalAlignment="Left" Margin="0,37,0,0" Name="showpicture" VerticalAlignment="Top" Width="410" />
<Image Height="365" HorizontalAlignment="Left" Margin="413,37,0,0" Name="image_processed" VerticalAlignment="Top" Width="410" />
</Grid>
</Window>[/code]
Can someone help me out?<br/>
Debugger shows that the assignment takes place.<br/>
<br/>
And while we are at it:<br/>
Why is there such a huge hirachie of datatypes preventing direct assignment of one datatype to another though the underlying purpose/data of is the same(e.g. Bitmap and Image for showing the picture? wouldnt it be easier of the datatypes to show the data would
just extend existing datatypes without having to make all the fuss using streams to get the data into the datatype?)<br/>
Thanks.
testing
<br/>
View the full article
Got a little problem with some code of mine.
I can assign an image, but the Source-Attribute is not retaining the value.
C#:
<pre class="prettyprint <pre style="font-family:Consolas; font-size:13; color:black; background:white <span style="color:#2b91af MemoryStream memstr;
<span style="color:#2b91af Bitmap toshow;[/code] private void processing(object sender, RoutedEventArgs e)
{
toshow = new Bitmap(thepicture);
Graphics graph = Graphics.FromImage(toshow);
graph.CompositingQuality = CompositingQuality.AssumeLinear;
graph.CompositingMode = CompositingMode.SourceOver;
int i = -1, j = -1,r,g,b,a;
System.Drawing.Color tmp;
while(++i<toshow.Width)
while (++j < toshow.Height)
{
tmp = toshow.GetPixel(i, j);
r = tmp.R - 20;
g = tmp.G - 20;
b = tmp.B - 20;
a = tmp.A;
b = (b < 0) ? 0 : b;
r = (r < 0) ? 0 : r;
g = (g < 0) ? 0 : g;
toshow.SetPixel(i, j, System.Drawing.Color.FromArgb(a, r, g, b));
}
memstr = new MemoryStream();
toshow.Save(memstr, System.Drawing.Imaging.ImageFormat.Bmp);
BitmapImage thisisso****ingstupidofms= new BitmapImage();
thisisso****ingstupidofms.CacheOption = BitmapCacheOption.OnLoad;
thisisso****ingstupidofms.StreamSource = memstr;
#error Source will not retain value.Why???
image_processed.Source = thisisso****ingstupidofms;
} [/code]
XAML<br/>
<pre class="prettyprint <Window x:Class="MutliMediasysteme_Mustererkennung_bsp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="453" Width="845
<Grid>
<Image Height="365" HorizontalAlignment="Left" Margin="0,37,0,0" Name="showpicture" VerticalAlignment="Top" Width="410" />
<Image Height="365" HorizontalAlignment="Left" Margin="413,37,0,0" Name="image_processed" VerticalAlignment="Top" Width="410" />
</Grid>
</Window>[/code]
Can someone help me out?<br/>
Debugger shows that the assignment takes place.<br/>
<br/>
And while we are at it:<br/>
Why is there such a huge hirachie of datatypes preventing direct assignment of one datatype to another though the underlying purpose/data of is the same(e.g. Bitmap and Image for showing the picture? wouldnt it be easier of the datatypes to show the data would
just extend existing datatypes without having to make all the fuss using streams to get the data into the datatype?)<br/>
Thanks.
testing
<br/>
View the full article