|
I'm writing some code that builds a custom file that combines several additional bits of non-image info along with the image file itself. I can create the file just fine, but when I try to load the file and extract the image from it, I get the following exception from PresentationCore :
The image data generated an overflow during processing.
The inner exception is:
Overflow or underflow in the arithmetic operation.
I load the image as a file stream and saving the resulting array of bytes via serialization. I deserialize to load the file and call this method to retrieve the image (the exception is thrown when it calls Bitmapimage.EndInit() ):
public static BitmapImage BitmapImageFromBytes(byte[] bytes, int desiredX, int desiredY)
{
BitmapImage image = null;
MemoryStream stream = null;
try
{
stream = new MemoryStream(bytes);
stream.Seek(0, SeekOrigin.Begin);
image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.DecodePixelWidth = desiredX;
image.DecodePixelHeight = desiredY;
image.EndInit();
}
catch (Exception ex)
{
if (ex != null) {}
throw;
}
finally
{
stream.Close();
stream.Dispose();
}
return image;
}
"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
|
|
|
|
|
I rather suspect the problem is to do with the Decodes - try not setting them.
"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
|
|
|
|
|
Well, removing those lines removed the exception, but the image doesn't display. :/
I set Image.Source to the retrieved BitmapImage , but I get nada on the screen. I verified that the BitmapImage object contains sane data (the DPI and resolution of the image are correct). What am I missing?
"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 is absolute hell, in fact, I blogged about it. If your image control is inside a grid or not, can make a difference. Check my blog ( link below ) for more details, they escape me right now, but basically, I once spent a few hours trying to work out why my image was not shown, and the reason was the control kept a size of 0, which changed when I changed the parent control.
And I spent several hours today trying to make a BitmapImage load a bitmap to be the size it was on disc, all to no avail. I do know that if the DesiredXXX properties work at all, you should set one and it will use that one, and maintain the aspect ratio. You could try that.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Try using this method instead:
public static BitmapImage BitmapImageFromBytes(byte[] bytes)
{
BitmapImage image = null;
MemoryStream stream = null;
try {
stream = new MemoryStream(bytes);
stream.Seek(0, SeekOrigin.Begin);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
image = new BitmapImage();
image.BeginInit();
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
image.StreamSource = ms;
image.StreamSource.Seek(0, SeekOrigin.Begin);
image.EndInit();
}
catch (Exception ex)
{
if (ex != null)
{
}
throw;
}
finally {
stream.Close();
stream.Dispose();
}
return image;
} This requires you to import System.Drawing , but it does the job.
"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
|
|
|
|
|
Worked like a champ. Many thanks.
"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
|
|
|
|
|
No probs mate.
"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
|
|
|
|
|
John Simmons / outlaw programmer wrote: image.DecodePixelWidth = desiredX;
image.DecodePixelHeight = desiredY;
image.EndInit();
I found out tonight that this is a waste of time. I spent ages trying to load an image to be the same size it was on disc, and while the PixelWidth and PixelHeight would be correct, nothing I did could get the actual Width and Height to be right. To be clear, I found it was next to impossible to take an 800x600 jpg on my hard drive, and load it in WPF to be 800 x 600 in size.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I think you mentioned it in another post, but it's due to the DPI and the way wpf displays images...
link[^]
|
|
|
|
|
Yeah,the whole DPI thing is an absolute nightmare. I tried to do something like what you linked to, but it was too complex in the context of our program, I couldn't get the image control to size how I wanted it to.
My main point was, I requested an image of a specific size and got something else back - the framework is just a nightmare in this regard.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi all,
I am in the following situation: I am writing my own "application framework" *WOW* - just for myself, nothing generally interesting There I want to implement a base class for applications - lets call it AppBase which is derived from System.Windows.Application. A concrete WPF application is to use AppBase as base class for the partial class MyApp.App in the file App.XAML.cs.
Now when compiling a concrete WPF application a code generator transforms the XAML code of MyApp.App into c# and puts System.Windows.Application as base class for the generated part in App.g.cs.
This leads to the situation that the compiler complains that I am not to use different base classes for my partial class MyApp.App.
What I am wondering is: Is there a way to tell the code generator which base class to use?? Any other way to enable the specification of custom base classes for WPF applications is also wellcome.
Thanks in advance.
Lars
#pragma error( disable : * )
|
|
|
|
|
Hi,
I am working on a RSS feeds application using Silver light 2.0. In this I am using WPF service for solving the cross domain problem. But for this web service I have to use System.ServiceModel.Syndication namespace. For adding this to my application to my application I looked in Add reference --> .Net tabs but I cannot find it there.
Please reply me how can I add this to my application.
Thanks in Advance
|
|
|
|
|
You can't. Silverlight uses a separate set of Silverlight assemblies because these are the ones that are available at the client end as part of the Silverlight download. This means that you get a subset of WPF/.NET functionality.
"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
|
|
|
|
|
If you upgrade your application to Silverlight 3, the Syndication classes are there.
"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 have 3 controls using in a wpf window..textbox, listbox and listview.
The textbox is like a searching textbox, where i search for Folder's in a particular folder, the list of searched folders will be displayed in listbox. I am able to do until this part.
Now, if I select any of the displayed folders in the listbox, then the files available in the particular folder should be displayed in the ListView. (missing out the link b/w the 2 here).
eg : I have 3 folders displayed in listbox (say folder1, folder2, folder3).each folder has few excel files. I selected folder 2 ( which has 5 excel files, mark.xls, steve.xls, cary.xls, rick.xls and jenny.xls and also a subfolder inside that called Launch1).
Now, the List view should show the folder2 contents divided into 3 columns, ( col1, col2, col3).
Name Desc Date
-------------------------------------------------------------------------------------------------------------
Mark this is mark's excel 07/20/2009
steve this is steve's excel. 07/22/2009
cary ............ ..................
rick .................... ........................
jenny .................... ...........................
------------------------------------------------------------------------------------
+ Launch1
Again Launch1 folder might have few workbooks, so I have put a plus on it.. so when + is clicked.. it shuold display the files inside this folder.
I am using Xaml and C#... please help.
Thank You,
Ramm
|
|
|
|
|
Which bit are you stuck on ? What have you already written ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I am following Sergey Zwezdin's blog "Windows 7 programming: Taskbar. Part 5 – CustomWindowsManager[^]" for creating the CustomWindowManager object.
As much as I gone thru the code, I realised that, I can create a custom preview window for the Windows 7 taskbar for the Window using it's handle. I want to do the same thing for the UserControl. How can I achieve this, as this only takes parameter of Windows & Windows handle.
My problem is: on click of a button I will create an object of an UserControl & then I will display it on the screen as a MwiChildWindow (Just like MDI form). I am able to create the MwiWindow & it's children but unable to show the child in the Taskbar previews. If I have four child windows (UserControls) visible in the main Window... I am getting only one preview of the Window.
I want to create 5 previews (1 MainWindow & 4 opened Child Window) to be visible in the pane.
Can anyone please guide me to resolve the same as early as possible? I didn't find anything on the net.
I am using Visual Studio 2008 SP1 (WPF 3.5 SP1) with Windows7APICodePack.
Looking forward... Thanks in advance.
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
After doing lots of analysis I got the solution. I am sharing the same for the benefit of others:
First we have to register the two events:
Taskbar.TabbedThumbnail.TabbedThumbnailActivated += new EventHandler<TabbedThumbnailEventArgs>(TabbedThumbnail_TabbedThumbnailActivated);
Taskbar.TabbedThumbnail.TabbedThumbnailClosed += new EventHandler<TabbedThumbnailEventArgs>(TabbedThumbnail_TabbedThumbnailClosed);
Then do the implementation of the registered events:
void TabbedThumbnail_TabbedThumbnailClosed(object sender, TabbedThumbnailEventArgs e)
{
}
void TabbedThumbnail_TabbedThumbnailActivated(object sender, TabbedThumbnailEventArgs e)
{
}
Now ehen you want to add the usercontrol... do the following steps:
TabbedThumbnailPreview thumnailPreview = new TabbedThumbnailPreview(this, myUserControl);
thumnailPreview.Title = "My UserControl Title";
thumnailPreview.InvalidatePreview();
Taskbar.TabbedThumbnail.AddThumbnailPreview(thumnailPreview);
That's it...
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
Whenever an item is selected in the listview I am wanting to basically just get the value of the first selected item in the first column.
It seems it is not done the same way in C# as with C# WPF. Could you provide me with somewhere I can learn how to do this?
|
|
|
|
|
I created an Expression MediaPlayer app with Encoder 2 using the SL2Gallery template. The app works perfectly stand-alone but I want to put the player on a page in another Silverlight 2 app. The playlist for the original app is supplied to the .xap through initParams. I copied the entire Page.xaml into my page (changed the namspace etc) and added the playlist to the player as follows. It almost works. I have three problems.
1. The playlist listbox acts as though the scroll area is only two items long. It's plenty big to show all of the items. Sometimes when scrolling a third item will show up, but it's intermittent.
2. The Thumbs don't display. I've tried every conceivable Build Action, but nothing seems to work. And yes I can see them added to the compilation during the build.
3. If the first two can be solved, I'd like it to auto start when the page opens.
<ExpressionPlayer:ExpressionPlayer Margin="0,0,0,0"
x:Name="myPlayer"
Style="{StaticResource GalleryTemplate}">
<ExpressionPlayer:ExpressionPlayer.Playlist>
<ExpressionMediaPlayer:PlaylistItem Title="Preparing Your Home"
MediaUrl="Properties/video1.wmv"
Description="My Description"
ThumbSource= "Properties/video1_Thumb.jpg"
FrameRate="25" />
<ExpressionMediaPlayer:PlaylistItem Title="2"
MediaUrl="Properties/video2.wmv"
ThumbSource="Properties/video2_Thumb.jpg"
FrameRate="25" />
<ExpressionMediaPlayer:PlaylistItem Title="3"
MediaUrl="Properties/video3.wmv"
ThumbSource="Properties/video3_Thumb.jpg"
FrameRate="25" />
<ExpressionMediaPlayer:PlaylistItem Title="4"
MediaUrl="Properties/video4.wmv"
ThumbSource="Properties/video4_Thumb.jpg"
FrameRate="25" />
</ExpressionPlayer:ExpressionPlayer.Playlist>
</ExpressionPlayer:ExpressionPlayer>
There is very little information on how to use the SL2Gallery template, so if someone could assist I'd appreciate it.
Thanks,
Steve
|
|
|
|
|
Hi Steve,
If you can send the sample project that you are having problems then I will try to see what I can help you.. The code that you pasted here seems fine to me.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
Michael,
I created a small app that just included the MediaPlayer in Blend 2 and it worked fine. As soon as I opened it in VS it transformed the project into a SL3 project and it stopped working. I guess I wasn't paying attention the first time. In an attempt to get everything into SL3 I downloaded Encoder 3 (I already have Blend 3), however now apparently Playlist doesn't contain PlaylistItems. At this point I'm totally confused. Plus, our neighbors are having a tree taken down and the noise is driving me crazy!!! I'm going to hang it up for the day and start fresh tomorrow.
Thanks for your offer of help and if I find anything tomorrow I'll post it,
Steve
|
|
|
|
|
Sorry to hear about those behavior in Silverlight 3 and Encoder. Feel free to let me know if you are having the same problem even you start fresh
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
Sorry I didn't get back on this; I got busy with other things. I worked it out by modifying the template code. Now it works beautifully!
Thanks for the help,
Steve
|
|
|
|
|
Give me some help please!
|
|
|
|