|
Can you give me an example with a RoutedEvent, i get crazy because i don't understand how it works.
|
|
|
|
|
Pass the control with the buttons in it into the other controls, and subscribe to its button click events. This violates basic OOP principles, but if that's what needs to be done to process events, then so be it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
This sounds like a good scenario for Commands. You can make your button trigger the pre-defined New command like so:
<pre><Button Command="New">Click Me</Button></pre>
Then you can wire up a command binding anywhere up the visual chain from the toolbar to handle the New command. That handler will need to be able to determine which control method to call (which is basically CG's first suggestion).
|
|
|
|
|
Hi, I need make any animation of sound for my WPF aplication. I don't know how to get any data for my animation. Maybe intensity from left and right canal? I don't know how to get this data. Can anybody help me? Thanks
|
|
|
|
|
Yes, balance and volume are about the only things you could animate.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I searched articles on this site, this forum, and MSDN and could not find an answer, even though the actual code is probably very simple. How do I perform a lossless 90 degree rotation to a JPEG file using strictly WPF API's? I've seen code for using GDI+ only. I can't believe I have to step out of WPF to do this. I also need to preserve metadata.
I'm already accomplishing this with lossy compression but to minimize artifacts I have to set quality at maximum and this is doubling the size of my images.
|
|
|
|
|
There is no such thing as lossless JPEG compression, unless you use a JPEG format which .NET does not support. Therefore, you need a third party library to support lossless JPEG, JPEG 2000, etc. If you're starting with a JPEG, then your image is lossy to start with, and a 90 degree rotation should not cause a great amount of additional loss.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: There is no such thing as lossless JPEG compression
You're absolutely right about that, but what I was asking about is how to rotate a JPEG or HD Photo image without doing another round of compression. If a JPEG file is rotated in 90 degree increments, theoretically it is possible to rotate it losslessly, and all self-respecting software does this.
I thought this was fairly well known information. In a previous application of mine that used GDI+ instead of WPF, you could rotate and save an image 100 times without the slightest image degradation. There's just got to be a way of doing this with WPF as well.
Conceptually what you have to do is separate the image data from the metadata and do a block by block transformation of the image data without going through the compression algorithm. But I just don't know the right calls to make in WPF to do all this heavy lifting for me. I don't think there's any way to do this if you start with the TransformBitmap and RotateTransform classes.
|
|
|
|
|
OK - given that an image exists in memory as pixel data, and not as JPEG compressed data, I'd have assumed that any rotation is lossless in memory, but that you need to apply JPEG compression in order to save the image. You're saying this is not the case ? How odd.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: given that an image exists in memory as pixel data, and not as JPEG compressed data
This assumption is wrong, that's your conceptual mistake. There has to be a way of reading the image data into memory intact, without using a decoder. Then you do the bit-twittling necessary to transform the raw image data. Nothing is ever decompressed or compressed in this process.
Christian Graus wrote: but that you need to apply JPEG compression in order to save the image
You're thinking in terms of the very classes that I said cannot be used.
Christian Graus wrote: You're saying this is not the case ? How odd.
That's precisely what I'm saying, and it's not so odd if you understand what I'm talking about. Evidentally you've never heard of lossless JPEG rotation, but what do you think Photoshop does, or any other self-respecting image processing software?
I mean if I have to go to GDI+ to accomplish this, I'll do it, but that would really rub me the wrong way. I didn't sign up to WPF to go outside of it every time I turn around.
modified on Wednesday, June 10, 2009 4:01 PM
|
|
|
|
|
fjparisIII wrote: This assumption is wrong, that's your conceptual mistake.
Well, no. Once your image is in a bitmap, it's raw data, it's not JPEG compressed.
fjparisIII wrote: There has to be a way of reading the image data into memory intact, without using a decoder.
OK, I get it now. You rotate it, as a JPEG, in memory, not as a bitmap. Thus keeping the artefacts you have, but not creating new ones ?
fjparisIII wrote: Evidentally you've never heard of lossless JPEG rotation, but what do you think Photoshop does, or any other self-respecting image processing software?
I was aware they did that, but I'd never taken the time to wonder what it meant. I believe the Atalasoft library we use for DICOM compression offers what you're talking about.
fjparisIII wrote: I mean if I have to I'll go to GDI+ to accomplish this, I'll do it, but that would really rub me the wrong way. I didn't sign up to WPF to go outside of it every time I turn around.
I wrote a program in WPF, it's basically an image viewer. Our images are huge, and memory management in WPF is a joke ( in fact, we hard reset the GC regularly, or WPF just flat out dies ). So, when we load images from our DB, we resize them to the size of the screen, and then reload as we zoom, to save memory. We have two types of image, illustrations that are pngs, and photos that are jpgs. I don't know if it's the format, or the type of data, but our jpegs, when resized, would get all sorts of horrible artefacts. I was a Microsoft MVP at the time, so I theoretically had a fast track to support. I reported this, they responded that there was no problem. I sent a sample app to show the issue, got the same response. I wrote back and insisted, they finally looked at it and admitted it was broken. This was .NET 3.0, two years ago. The bug is still there, and WPF still does not expose Dispose methods, or clean up after images properly. So, get used to horrible imaging support in WPF. We resize our images using GDI+.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: You rotate it, as a JPEG, in memory, not as a bitmap. Thus keeping the artefacts you have, but not creating new ones ?
Exactly. Now you get it.
Regarding your WPF application that resizes images to fit the display, my application does the same thing. I don't know if you'd call my images huge (they're from 12 MPixel Nikon cameras, so 4288x2848), but WPF scales them in about two seconds.
Are you using the CroppedBitmap class to do this? I don't bother with this. Instead I just set the Margin property of the Grid object that holds the System.Windows.Controls.Image object that lives inside the grid. It works pretty well. I even use the same technique for zooming around an image at 1:1. The margin just propagates down to the image. I never touch the original bitmap once it decoded. I just let WPF worry about it and since WPF goes directly to DirectX it's pretty fast.
In fact one of my beta testers (actually pre-alpha) is amazed by how fast my new app based on WPF rotates images compared to the original C++/MFC app that used GDI+, which I guess goes through gobs of layers. My new app basically rotates an image instantly even on his slow machine, whereas my original GDI+ app takes a couple seconds on his machine.
I also support saving resized images to disk. I haven't noticed the "horrible artifacts" that you report. I'm using .NET 3.5.
I'm also somewhat disconcerted by the lack of low level control over garbage collection under .NET, especially since my app offers batch operations that can process thousands of images in a background thread. But it seems to do okay, not really any worse than my original C++ app based on GDI+.
What I've found is that the time to load a program can be a problem if it needs dozens of pages it has to render during startup. It's that JIT compiling that's the bottleneck. I'm still in pre-alpha testing so I'm not too worried about performance yet, but eventually I'll have to load pages on a demand basis so that the app displays instantly, instead of rendering all 70 pages that are in the app currently before it gives control to the user. On my 64-bit machine with 8 GBytes of RAM, the program displays in 2 seconds, but on my beta tester's machine with 1 GByte of RAM, it takes 30 seconds to render the app. Ugh!
Where WPF really shines and blows old rendering technologies away is individual image processing operations: displaying (say) an image that is 1920x1440 on a monitor that size is instantaneous, whereas with my old C++ app using GDI+ it would take a couple seconds to render such an image.
There's huge promise in WPF. I just hope Microsoft doesn't give up on it.
modified on Wednesday, June 10, 2009 5:01 PM
|
|
|
|
|
fjparisIII wrote:
Are you using the CroppedBitmap class to do this? I don't bother with this. Instead I just set the Margin property of the Grid object that holds the System.Windows.Controls.Image object that lives inside the grid. It works pretty well. I even use the same technique for zooming around an image at 1:1. The margin just propagates down to the image. I never touch the original bitmap once it decoded. I just let WPF worry about it and since WPF goes directly to DirectX it's pretty fast.
Yeah, we did that. But, our images are actually bigger than that, and as the use of our app means swapping images a lot, WPF basically would crap out and crash in time. Initially, it worked great, we moved to this to try to get out of memory issues.
fjparisIII wrote: I also support saving resized images to disk. I haven't noticed the "horrible artifacts" that you report. I'm using .NET 3.5.
I just ran my test app, the one I sent Microsoft, and it still happens. Radiographs were the images that showed it the worst, others, you had to look for. Also, it only happens on certain resizings, that is, you could resize several times before suddenly it would go bad. My test app remembers a setting that destroyed this particular picture, and applies it every time.
fjparisIII wrote: I'm also somewhat disconcerted by the lack of low level control over garbage collection under .NET, especially since my app offers batch operations that can process thousands of images in a background thread. But it seems to do okay, not really any worse than my original C++ app based on GDI+.
If you ever find that your app crashes, just ask, I'll post the code to fix that. In fact, I'll post it on my new blog some time soon, anyhow.
fjparisIII wrote: What I've found is that the time to load a program can be a problem if it needs dozens of pages it has to render during startup.
Yeah, and WPF is so slow to load to start with, we use a Win32 app as our splash screen, b/c otherwise it just was not responsive, it took ages to appear.
fjparisIII wrote: On my 64-bit machine with 8 GBytes of RAM, the program displays in 2 seconds, but on my beta tester's machine with 1 GByte of RAM, it takes 30 seconds to render the app. Ugh!
Yeah, we have users with 256 MB, although we say 512 is the minimum. I HAVE been pleasantly surprised at how the app performs on notebooks with shared video, I expected that to be a non starter.
fjparisIII wrote: There's huge promise in WPF. I just hope Microsoft doesn't give up on it.
I believe WPF is what they wanted Winforms 1.0 to be. I doubt they will give up on it. I agree, it has a lot of promise, and certainly the apps we write with it are way cooler than anything we could easily do in Winforms.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi
I'm trying to create a 3D modeling app in WPF, my app reads values from a database and generates 3D models based on the dimensions read out from the database, everything works fine, except for my models looking a bit dull. Also, when I rotate the camera at a certain angle, I can't differentiate between the different models because they overlap and there's no clear distinction between them, as they're all the same color.
I've tried playing around with specular materials as well as different kinds of lighting, but I can't seem to get it right.
If anyone has already created a similar application, or any application where you worked with 3D models, please help me find the correct combination of materials and lighting.
|
|
|
|
|
I have a silverlight application which uses wcf service hosted in a wpf application, but when I try to connect more
then one client the second client always waits until the first client
completes the call.How can I make
WCF to accept calls from multiple clients at the same time?
|
|
|
|
|
See Here[^]
There's no need to post to multiple message boards. This is a WCF question,
this is the correct board.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a silverlight application which uses wcf service hosted in a wpf application, but when I try to connect more
then one client the second client always waits until the first client
completes the call.How can I make
WCF to accept calls from multiple clients at the same time?
|
|
|
|
|
I would start by setting the service ConcurrencyMode to Multiple
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple]
public class MyService : IMyService
{
...
If you have operations that take time and/or block (like pretty much any device
I/O operation does), which apparently you do, you should implement the service
operation(s) asynchronously:
Synchronous and Asynchronous Operations[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the answer,But I already used [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple],but the problem still exists,Also implemented the service as asynchronously,Could you suggest any other solutions?
|
|
|
|
|
I have no idea what's wrong.
It could be in host configuration, service configuration, or the service implementation.
I can't reproduce this, even without the [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)].
Even a synchronously implemented operation like
public string EchoStringSynchronous(string msg)
{
Thread.Sleep(10000);
return msg;
}
can be executed by multiple clients without a client having to wait for
another client's operation to complete.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I am working on WPF application. In this I have to save images into a folder named Slides which is in the application and I have to retrieve these images. But I am getting error with the path. I am able to access folder in some other drive but I am getting error when I directly access the folder.
string CanvasFile = "d:\\canvas" + Canvasnum + ".png";
util.SaveCanvas(this, this.canvasDesigner, 136, CanvasFile);
Image img = new Image();
img.Source = new BitmapImage(new System.Uri(@"D:\canvas.png"));
panel.Children.Add(img);
If anyone have idea to access the folder in the application directly lease reply me.
Thanks in advance.
|
|
|
|
|
Do you want to retrive the images from disk at runtime or use images that are part of the assembly?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Nekkantidivya wrote: I am working on WPF application. In this I have to save images into a folder named Slides which is in the application and I have to retrieve these images. But I am getting error with the path.
What is the error ?
It's not clear as to exactly what is the issue. Can you rephrase the question ?
|
|
|
|
|
Try this i am sure this will help u.
1.In Visual Studio, click the Project menu, and select Add Existing Item. Find and select the image you want to add to your project.
2.In the Solution Explorer window, right-click the image file you just added to your project, and select Properties from the popup menu. The Properties tool window appears.
3.In the Properties window (see picture below), change the Build Action property to Embedded Resource.
4.Build the project. The image will be compiled into your project's assembly.
Load Image Resource
Be sure to include the following namespaces in your project:
using System.IO;
using System.Reflection;
To load the image resource programmatically, use the following code:
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream = myAssembly.GetManifestResourceStream( "MyNamespace.SubFolder.MyImage.bmp" );
Bitmap bmp = new Bitmap( myStream );
The trickiest part of loading an embedded resource is getting the correct path. A resource path takes this form:
<namespace>.<subfolders>.<image name>.<extension>
where:
namespace is the namespace for the project
subfolders is the folder path within the project, with each folder separated by a period instead of a slash
image name is the name of the image file
extension is the image file extension (for example, "bmp" or "jpg")
|
|
|
|
|
Hello,
What i am doing is, i am creating a Datatable based on values that user fills up in the form.
Further i am assigning that datatable to the WPF datagrid to display the Grid.
dgMatrix.ItemsSource = GetDataSource.DefaultView
Now, as the user edits the grid and presses the SAVE button under the grid, I would like to save all the rows of the Grid into a new table in the database.
Is there a way to loop through each row of the Grid and then inserting each record into the database??
In ASP.net i was using the following function:
'For Each row As GridViewRow In dgMatrix.Rows
'
' Dim checkbox As CheckBox = CType(row.FindControl("cbRows"), CheckBox)
' If checkbox.Checked Then
' Try
' Dim txtFromPorts As TextBox = CType(row.FindControl("txtPortsFrom"), TextBox)
' Dim txtToPorts As TextBox = CType(row.FindControl("txtPortsTo"), TextBox)
' Dim txtFType As TextBox = CType(row.FindControl("txtFareType"), TextBox)
' Dim txtFClass As TextBox = CType(row.FindControl("txtFareClass"), TextBox)
' Dim txtLowGAmt As TextBox = CType(row.FindControl("txtGrossAmtLow"), TextBox)
' Dim txtLowNAmt As TextBox = CType(row.FindControl("txtNettAmtLow"), TextBox)
' Dim txtHighGAmt As TextBox = CType(row.FindControl("txtGrossAmtHigh"), TextBox)
' Dim txtHighNAmt As TextBox = CType(row.FindControl("txtNettAmtHigh"), TextBox)
' Dim txtPeakGAmt As TextBox = CType(row.FindControl("txtGrossAmtPeak"), TextBox)
' Dim txtPeakNAmt As TextBox = CType(row.FindControl("txtNettAmtPeak"), TextBox)
' ' Dim dr As DataRow = dtNew.NewRow
' strFrom = txtFromPorts.Text
' strTo = txtToPorts.Text
' strFareType = txtFType.Text
' If txtFClass.Text.Trim <> "" Then
' strFareClass = txtFClass.Text
' End If
' If txtLowGAmt.Text <> "" Then
' strGrossLow = txtLowGAmt.Text
' End If
' If txtLowNAmt.Text <> "" Then
' strNettLow = txtLowNAmt.Text
' End If
' If txtHighGAmt.Text <> "" Then
' strGrossHigh = txtHighGAmt.Text
' End If
' If txtHighNAmt.Text <> "" Then
' strNettHigh = txtHighNAmt.Text
' End If
' If txtPeakGAmt.Text <> "" Then
' strGrossPeak = txtPeakGAmt.Text
' End If
' If txtPeakNAmt.Text <> "" Then
' strNettPeak = txtPeakNAmt.Text
' End If
' 'Check if the checkbox is checked.
' strSQL = "INSERT INTO FareInfo (" + _
' "FareId," + _
' "PortsFrom," + _
' "PortsTo," + _
' "FareType," + _
' "FareClass," + _
' "GrossAmtLow," + _
' "NettAmtLow," + _
' "GrossAmtHigh," + _
' "NettAmtHigh," + _
' "GrossAmtPeak," + _
' "NettAmtPeak" + _
' ") VALUES ("
' If (strFareId <> "") Then
' strSQL = strSQL + "'" + strFareId + "',"
' strSQL = strSQL + "'" + strFrom + "',"
' strSQL = strSQL + "'" + strTo + "',"
' strSQL = strSQL + "'" + strFareType + "',"
' strSQL = strSQL + "'" + strFareClass + "',"
' If strGrossLow <> "" Then
' strSQL = strSQL + " " & strGrossLow & " ,"
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strNettLow <> "" Then
' strSQL = strSQL + "" + strNettLow + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strGrossHigh <> "" Then
' strSQL = strSQL + "" + strGrossHigh + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strNettHigh <> "" Then
' strSQL = strSQL + "" + strNettHigh + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strGrossPeak <> "" Then
' strSQL = strSQL + "" + strGrossPeak + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strNettPeak <> "" Then
' strSQL = strSQL + "" + strNettPeak + ""
' Else
' strSQL = strSQL + " " & "null" & " "
' End If
' strSQL = strSQL + ")"
' End If
' DBClass.ExecuteQuery(strSQL)
' gvMatrix.Visible = False
' 'Insert 1 row in Progress grid
' Catch ex As Exception
' End Try
' End If
'Next
Can someone suggest me the right way to do so in WPF. I would really appreciate that, Thanks.
|
|
|
|
|