|
|
|
Okay, I subscribed to the three events in C# code and ran the app and when it hit the BitmapEncoder.Save() call, my message box produced the following output:
It would probably fail on all images, but the first one it failed on is the following:
C:\temp\ImageScaling\SelectedImages\jpg\001.jpg
Reason: The image data generated an overflow during processing.
This is what I have also been getting with all versions of my code that I have tested with, including my own reimplementation of BackgroundWorker that I tested with yesterday. This time I took a breakpoint where I output this message so I could recover some details about the exception that my message box does not display:
HResult: -2146233066
innerException: {"Overflow or underflow in the arithmetic operation."}
message: The image data generated an overflow during processing.
So the overflow the Exception.Message property is talking about is an arithmetic overflow. So BitmapEncoder.Save() is probably getting an empty buffer or something with all zeroes in it and when it tries to encode the JPEG image data it generates an arithmetic overflow. So the real question is, why doesn't BitmapEncoder.Save() have the actual image data to work with?
I think this conclusively proves that whether BackgroundWorker runs as STA or MTA has nothing to do with my problem, what I expected all along.
modified on Sunday, June 7, 2009 1:15 PM
|
|
|
|
|
fjparisIII wrote: I think this conclusively proves that whether BackgroundWorker runs as STA or MTA has nothing to do with my problem
Right, but your very first post had this:
"The code that I have developed based on the above thread works 100%
of the time if it is executed inside of the WPF main application thread.
But it fails 100% of the time if it is executed inside of a worker thread.
The code fails on BitmapEncoder.Save(), throwing a "Cannot write to the
stream" exception. But I have to execute this code inside of a worker
thread because I have to display a progress bar: I'm updating the Copyright
metadata in a batch operation for thousands of images!"
That's what I was addressing...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
There are a couple of posts you made I have to respond to. I'll do this one first because it's the easiest.
You were responding to the following quote from a previous post of mine:
Mark Salsbery wrote: your very first post had this:
"The code that I have developed based on the above thread works 100%
of the time if it is executed inside of the WPF main application thread.
But it fails 100% of the time if it is executed inside of a worker thread.
The code fails on BitmapEncoder.Save(), throwing a "Cannot write to the
stream" exception. But I have to execute this code inside of a worker
thread because I have to display a progress bar: I'm updating the Copyright
metadata in a batch operation for thousands of images!"
That's what I was addressing...
There are actually three places in my application where I call BitmapEncoder.Save() to capture image metadata that I need to add to an encoded image. One was already running in the main UI thread and was never a problem. The one I'm talking about in the above quote attempts to write "friendly" metadata tags in a batch operation with potentially thousands of files (e.g. the copyright notice). I solved that one with the "kludge" I talked about earlier, of pulling that small piece of code out of the background thread and executing it in the UI thread.
The one I'm still having problems with is a batch operation that scales images, where I have to transfer all of the metadata from the original image to the scaled image.
modified on Sunday, June 7, 2009 1:16 PM
|
|
|
|
|
fjparisIII wrote: So the real question is, why doesn't BitmapEncoder.Save() have the actual image data to work with?
That IS the real question
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
fjparisIII wrote: the next step of passing some source code to you via email and giving you my running application (which you'll be able to get from the Office Live site)
msalsbery at hotmail dot com
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
fjparisIII wrote: I just hope you don't run out of patience with me
Heh no problem - it's all a learning experience
fjparisIII wrote: how to do basic things like extending the namespace of XAML
Same as you did for the "cm" namespace in your sample above. For example
the code I posted was in the WPFTester namespace, so I use something like this:
xmlns:local="clr-namespace:WPFTester"
Note I didn't need to specify an assembly, because its in the same assembly as the XAML.
Anyway, I was under the impression from your previous posts that you were
already using a BackgroundWorker, and if so, you should have known what
RunWorkerAsync() does (your background thread wouldn't run without calling
it) and how to add a DoWork event handler, which is the code that runs on the
background thread.
I don't know how you do it from XAML - I use code, and it looks something like this:
<code>
WPFSTABackgroundWorker bw = new WPFSTABackgroundWorker();
bw.WorkerReportsProgress = true;
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.RunWorkerAsync();
...
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
<code>
WPFSTABackgroundWorker bw = sender as WPFSTABackgroundWorker;
for (int i = 0; i < 10; i++)
{
bw.ReportProgress(i * 10);
Thread.Sleep(500);
}
}
void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
<code>
progrssBar.Value = e.ProgressPercentage;
}
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
<code>
MyScaleButton.Content = "Thread completed!";
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
None of this is really relevant anyway - I did that class to fix the problem
you fixed with the kludge
There's no reason not to use BackgroundWorker if it works.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
I'm here - I'm just saying since the potential MTA/STA thread problem in
your original post is no longer an issue, my thread class isn't going to
help you any - just use BackgroundWorker
fjparisIII wrote: I don't know how to get XAML to recognize my Page.Resources block when it is no longer BackgroundWorker.
Maybe a typo somewhere - I tried your XAML and it worked for me.
Here's a snippet (note I call mine "local" by convention)
<Window x:Class="WPFTester.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTester"
Title="Window3" Background="SteelBlue" >
<Window.Resources>
<local:WPFSTABackgroundWorker
x:Key="backgroundWorker"
WorkerReportsProgress="True"
WorkerSupportsCancellation="True"
DoWork="BackgroundWorker_DoWork"
ProgressChanged="BackgroundWorker_ProgressChanged"
RunWorkerCompleted="BackgroundWorker_RunWorkerCompleted"
>
</local:WPFSTABackgroundWorker>
...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
What are the steps to reproduce the error on the uploaded app?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am now using a new class based on the code you supplied. This has enabled me to get rid of my "kludge." It works in case I only need to add new metadata items but not in case I have to copy the entire BitmapMetadata object from one image to another. That remains a profound mystery and Microsoft has not responded to my Connect inquiry, probably because it involves a bug in a release product (.NET 3.5) and I don't think Microsoft owns up to those.
|
|
|
|
|
Hi
I recently got it working to bind my XML document to my treeview by doing the following in the code behind file:
XDocument doc = XDocument.Load("path\\dsCurrent.xml");
_treeView.DataContext = doc;
and the following in the XAML:
<Window.Resources><br />
<HierarchicalDataTemplate ItemsSource="{Binding Path=Elements}" x:Key="TVTemplate"><br />
<TreeViewItem Header="{Binding Path=Name}"/><br />
<!--<TreeViewItem Header="{Binding Path=Attribute[Title].Value}"/>--><br />
</HierarchicalDataTemplate><br />
</Window.Resources><br />
<StackPanel><br />
<TreeView x:Name="_treeView" ItemsSource="{Binding Path=Root.Elements}" ItemTemplate="{StaticResource TVTemplate}"/><br />
</StackPanel>
Now my XML file looks like this:
- <Shippers><br />
<ShipperID>1</ShipperID> <br />
<CompanyName>Speedy Express</CompanyName> <br />
<Phone>(503) 555-9831</Phone> <br />
- <Orders><br />
<OrderID>10249</OrderID> <br />
<CustomerID>TOMSP</CustomerID> <br />
<EmployeeID>6</EmployeeID> <br />
<OrderDate>1994-08-05T00:00:00+02:00</OrderDate> <br />
<RequiredDate>1994-09-16T00:00:00+02:00</RequiredDate> <br />
<ShippedDate>1994-08-10T00:00:00+02:00</ShippedDate> <br />
<ShipVia>1</ShipVia> <br />
<Freight>11.61</Freight> <br />
<ShipName>Toms Spezialitäten</ShipName> <br />
<ShipAddress>Luisenstr. 48</ShipAddress> <br />
<ShipCity>Münster</ShipCity> <br />
<ShipPostalCode>44087</ShipPostalCode> <br />
<ShipCountry>Germany</ShipCountry> <br />
- <_x005B_Order_x0020_Details_x005D_><br />
<OrderID>10249</OrderID> <br />
<ProductID>14</ProductID> <br />
<UnitPrice>18.6</UnitPrice> <br />
<Quantity>9</Quantity> <br />
<Discount>0</Discount> <br />
</_x005B_Order_x0020_Details_x005D_>
When I start the app, my treeview gets created correctly, except it does not put the actual ShipperID value in as the name of the node, it shows "SupplierID". This is the same for all the nodes. How can I bind the Header of the treeview items so that it shows the values? I tried binding the header to Value but it then shows a whole bunch of information. How can I select specifically which value to set as the header for the treeview items?
|
|
|
|
|
Etienne_123 wrote: t does not put the actual ShipperID value in as the name of the node, it shows "SupplierID". This is the same for all the nodes. How can I bind the Header of the treeview items so that it shows the values?
Maybe bind to Value instead of Name?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I actually said in the last part of my messge that I've tried that, but it then shows the shipperID, name, address all together. Is there anything else I can bind to? How can I specify which field I want to bind to? Or would I have to use XPath. But then another question arises, if the xml is not included in my xaml file within a XmlDataProvider, how do I use XPath on an external xml file?
|
|
|
|
|
Etienne_123 wrote: I actually said in the last part of my messge that I've tried that, but it then shows the shipperID, name, address all together
Something was incorrect then.
Etienne_123 wrote: Is there anything else I can bind to?
Sure - I gave you this link in the first thread you posted on this topic:
How to: Bind to XDocument, XElement, or LINQ for XML Query Results[^]
You may have to follow links from that page "To learn more"...
Etienne_123 wrote: if the xml is not included in my xaml file within a XmlDataProvider, how do I use XPath on an external xml file?
I believe I've mentioned XmlDataDocument in a previous post. Or maybe its base class
XmlDocument. Or other sources - Binding Sources Overview[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
I'm using a typed dataset in my WPF app which was generated for me by adding a new data source via the visual studio wizard. My problem is, when I call the WriteXml
method on my dataset (e.g. dsDemo.WriteXml) it creates an XML file yes, but the only thing in the XML file is the following:
<?xml version="1.0" standalone="yes" ?>
<_Workstation_aXYZDataSet xmlns="http://tempuri.org/_Workstation_aXYZDataSet.xsd" />
Why does it not show all my table data?
|
|
|
|
|
This question has absolutely nothing to do with WPF, and you've cross posted in the C# forum. Please don't do this - it's really bad form.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
I want to use Number updown control in my WPF application. BUt I didn't found any such control in the toolbox control. Please tell me how can i implement this control and its functionality in my application
If any one have idea on this please reply me.
Thanks in advance.
|
|
|
|
|
There is no NumericUpDown control for WPF inherently available (as far as I know). But you can always use the Winform NumericUpDown control (using a WindowsFormsHost[^]).
Take a look at this sample on MSDN[^].
|
|
|
|
|
I developed a UserControl for a spinner composed of an edit box and a vertical scroll bar. To make it general enough required 400 lines of code but it has proved to be so useful that I've employed it in dozens of different places in my application and it has given me enormous payback. So just read a book explaining how to develop your own UserControl. Knowing how to do this should be knowledge at the fingertips of every WPF programmer anyhow. It's simply part of being a WPF programmer and Microsoft is right about not supplying dozens of little gizmos that would be "nice to have" when the framework itself has been so carefully designed for developers to "roll their own."
|
|
|
|
|
Hi,
I am working on a silver light application. In this I want to use a web browser control like functionality. That is I want to open a new browser dynamically at run time to open a new web link. I tried in many ways using the normal syntax but they didn't worked with my application. please note that I am using Silver light 2.0
If any one have any idea on this please reply me.
Thanks in advance.
|
|
|
|