|
I had already tried 2904,5000 and didn't see anything. You could try forcing software rendering and see if it is a driver issue if not I don't have any more ideas.
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;
|
|
|
|
|
Insincere Dave wrote: I had already tried 2904,5000 and didn't see anything.
I tried your code at 3008 and 5000, with my original image at 4288x2848. Resizing to 5000, the artifacts are so horrendous that the original image is barely visible. That same image at 3008 had some barely detectable artifacts, so perhaps you have some extremely simple image that doesn't show the problem. Try a full resolution, digital photograph of people from a modern 12 MPixel DSLR with a variety of colors from clothing and skin tones.
Insincere Dave wrote: You could try forcing software rendering and see if it is a driver issue
I'm not sure how your example would be used. RenderTargetBitmap also uses software rendering and at least I can get my arms round that. Would that accomplish the same thing you're suggesting?
Just a little more background: The original purpose of my scaling function was to provide a batch operation to scale full resolution images straight out of the camera down to a size that can be shown on commonly available monitors 1:1 in a photo viewing application. The batch operation can operate on a single folder or recursively, down a folder tree, so the batch operation can theoretically scale thousands of images with a single mouse click, writing them to another folder tree that mirrors the original, only containing scaled down images. There are no commonly available monitors with resolutions > 2900x2900 and so in my original testing, I never ran across this problem.
But one of my beta testers "graduated" from a 6 MPixel digital SLR to a 12 MPixel digital SLR and found working with 3008x3008 images was a lot more convenient than working with 4288x4288 images. So he tried to use my program to perform this scaling. That's how he ran into the problem.
|
|
|
|
|
Insincere Dave wrote: You could try forcing software rendering and see if it is a driver issue
I don't know how to use that HwndSource.CompositionTarget.Render mode example you gave. I asked you for an example of how to use it, and you did not respond. But I tried forcing software rendering with the RenderTargetBitmap class and it did not produce the artifacts I'm seeing using the hardware rendering that WPF uses through DirectX. However, the quality of the bitmap rendering was dismal, so it could not be used in a production program for showing photographs.
When you say, "to see if it is a driver issue," do you mean a video driver issue? (WPF uses DirectX for all video output and DirectX uses the video driver.) I don't think this is a video driver issue for the following reason. I tried running my program on another machine with completely different video hardware and hence a completely different video driver and I got exactly the same artifacts on all images.
Insincere Dave wrote: I had already tried 2904,5000 and didn't see anything.
You must be using a very peculiar image. Try a regular photograph of people with colorful clothing and normal skin tones. You'll be sure to see the artifacts. Don't simply scale up a small jpeg to 5000 either, because, as the tests that I've published on this thread show, if you scale a small image up, you can make huge images without producing artifacts. Start with a native JPEG from at least a 6 MPixel camera, take a picture of family or friends, and scale the 3000x2000 image to 5000 and you'll be sure to see the artifacts. They will be so bad you will hardly recognize the original image. The artifacts will completely overlay the entire image, practically obliterating the original.
A more practical test would be to scale a 4288W image from a 12 MPixel camera to a 3000W image. That will also surely demonstrate the problem.
|
|
|
|
|
The software rendering code goes in the loaded event and you apply it to the window, but im not sure it will have any effect if you are just saving the image and not displaying it. I've been working with a high res (5k by 7x) photo and haven't seen anything yet. Im using VS 2010 on vista but have tried targeting both 3.0 and 3.5 and checked they are referencing the correct version. I have also installed the platform update for vista which may have updated the windows imaging component. This thread is the only one i've found that might be applicable but I think you'll have to contact microsoft or try their wpf forums.
|
|
|
|
|
Insincere Dave wrote: The software rendering code goes in the loaded event and you apply it to the window, but im not sure it will have any effect if you are just saving the image and not displaying it.
In my original application, I'm just saving it and not displaying it, but I've written a test application based on code you provided where I just display it and don't save it. I was actually surprised when I saw the bug appear even in this simplified code. I've written the following function, based on code you provided, and this function demonstrates the problem with 100% reliability in 10 different images from my Nikon D2X camera:
void ScaleBitmapImage(string imagePath, double targetSize, Image image)
{
Uri uri = new Uri(imagePath);
BitmapImage bitmapImage = new BitmapImage(uri);
var scale = targetSize / bitmapImage.PixelWidth;
TransformedBitmap scaledBitmap = new TransformedBitmap();
scaledBitmap.BeginInit();
scaledBitmap.Source = bitmapImage;
scaledBitmap.Transform = new ScaleTransform(scale, scale);
scaledBitmap.EndInit();
image.Source = scaledBitmap;
}
Insincere Dave wrote: Im using VS 2010 on vista
I'm using VS 2008 on Vista, but I have installed VS 2010. I just haven't gotten around to trying it out yet on 2010. Maybe I should try that next.
Insincere Dave wrote: I have also installed the platform update for vista which may have updated the windows imaging component.
I've been Googling around trying to figure out how to download this update and I haven't found anything definitive. I've seen plenty of references to it but no specific link to a download page. I followed Microsoft's instructions at this link:
http://support.microsoft.com/kb/971644[^]
But when I follow the instructions, the closest thing it lists in the Windows Update List is an item called, "Update for Windows Vista for x64-based systems - English (KB937286)". Hopefully that is the same thing as the Platform Update for Vista. I'm about to do that now, which of course means rebooting my machine. I'll let you know how things turn out. I'd love to be able to tell my customers what needs to be done to solve this horrendous bug.
|
|
|
|
|
Well, that update I mentioned (KB937286) wasn't the Platform Update for Vista, but something that just came out today. Also, VS 2010 doesn't solve the problem. I converted my little application to VS 2010 and the problem still shows up. I guess I'll have to keep searching for the download page for the Platform Update for Vista. I don't know why the Microsoft download page doesn't show up when I Google for it, only a bunch of pages that mention that it's been released, and I haven't found any of those pages giving the link to the download page.
|
|
|
|
|
|
Yes, I found that link and followed the instructions. I didn't find a reference to the Platform Update for Vista. So I investigated further and saw that before the Platform Update can be installed, you have to have Vista SP2 installed, which I didn't! As I type, it is ready to be installed. After it gets installed, 971644 will hopefully show the Platform Update available for installation. Right now I have to shut everything down before the SP2 installation will start!
|
|
|
|
|
Incredible! Getting the Platform Update for Vista installed did the trick! Thank you so much for sticking with me! So this is probably not a problem under Windows 7, and I don't think there's a fix for it under XP. I'll have to document that in my application.
|
|
|
|
|
Im glad that fixed it, I thought that was kind of a long shot really. I tried scaling an Image control and using RenderTargetBitmap and didn't notice any quality degradation so that might be a workaround for xp, there are some other options like System.Drawing aswell.
|
|
|
|
|
Insincere Dave wrote: I tried scaling an Image control and using RenderTargetBitmap and didn't notice any quality degradation
I'm probably doing something wrong. Is your code small enough to quote here so I can see how you did this?
|
|
|
|
|
There is a recent update for WIC for xp that might contain the fix.
This code might still cause the artifact you could try setting the BitmapScalingMode if it does.
void ScaleUsingRTB(string inFile, string outFile, double scale)
{
Uri uri = new Uri(inFile);
BitmapImage bitmapImage = new BitmapImage(uri);
var image = new Image
{
Source = bitmapImage, Width = bitmapImage.PixelWidth*scale, Height = bitmapImage.PixelHeight*scale
};
image.Measure(new Size(image.Width,image.Height));
image.Arrange(new Rect(0,0,image.Width,image.Height));
RenderTargetBitmap rtb = new RenderTargetBitmap((int) image.Width, (int) image.Height, 96, 96, PixelFormats.Pbgra32);
rtb.Render(image);
Save(outFile,rtb);
}
|
|
|
|
|
The code you supplied does work and at least superficially (without "pixel-peeping") provides good quality. Of course the following line does not compile:
Insincere Dave wrote: Save(outFile,rtb);
but can be replaced with code that does and the scaled image file does not contain artifacts, even on an XP system.
In Googling, I was surprised by how many people can't get RenderTargetBitmap to work, complaining of blank images. I tried some of the code posted that supposedly works and I also got blank images, and solutions posted that supposedly fixed the blank images did not work. But your code works, and I never saw anyone post that solution. Where did you get it, or did you just figure it out? The code I've seen posted is also considerably more complicated than what you posted.
In any case, I now have software rendering code that I can use for XP systems and Vista systems not up to SP2. Once again, thank you very much.
I'm not even going to try the WIC solution because I don't want to contaminate my application with COM code.
|
|
|
|
|
I can't remember where I first saw code using RenderTargetBitmap, you need to call measure and arrange if the item hasn't been added to the visual tree otherwise it's not necessary. WPF uses WIC so that patch might still be applicable but I don't know if it will fix the issue.
|
|
|
|
|
Thanks for the explanation for using Measure and Arrange. I'm still trying to get my head around those two functions.
I haven't performed any measurements, but using software rendering doesn't appear to be all that much slower than using the video card, even on my wife's entry level PC running XP. (It does have 2 GB RAM, however.) I guess modern PC CPU's rival video card GPU's for simple things like bitmap rendering. So I'm not (yet) motivated to see whether the new WIC for XP solves the problem. I suspect it does, but I'm thinking, so what? Software rendering seems to be working fine in my application.
|
|
|
|
|
Hi,
Any idea how to increase/decrease the horizontal spacing between the nodes in a treeView??
Thank you guys!
|
|
|
|
|
Maybe adjust the left margin on the element that displays the node.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I adjusted Padding on the Label that I put in the node and my problem has solved
|
|
|
|
|
Hi, i am not sure if this is a good place to ask the following, but...
is there a method to export/import a playlist into Windows Media Player (10 and above?)
I'm creating a media manager database in Access 2007. I will have a collection of various files (audio, video, images, .PPT, .DOC, ..). If i could build a playlist containing a collection of my files, I want a format that can be imported into Windows Media Player.
I see iTunes has a feature that allows Import/Export of a playlist and thought something might also exist in the Microsoft environment.
Thanks.
|
|
|
|
|
|
This is a silverlight forum, so unless you are doing something with it, this is not the best place to ask this question.
The Lounge[^] may be a good place to bring this up (so long as you're dont discuss any code related issues there).
|
|
|
|
|
Hi,
I am working on a silverlight application. In this I created a silverlight page named Page.xaml. Then this silverlight page is used or embedded in a aspx page named Home.aspx. In Home.aspx I wrote javascript function. This javascript function should be called whenever I click on the button in Page.xaml.
i.e., on clicking a button in Page.xaml I have to call the javascript function in Home.xaml provided Page.xaml is in Home.aspx and all these are in a same project.
If anyone have any idea to do this please reply me.
Thanks in advance.
|
|
|
|
|
|
|
Hi Nekkantidivya,
Use HtmlPage.Window.Invoke() method to give the JavaScript call from your silverlight application.
Suppose the name of your javascript method is: SayHello(), then call the following from your button click event implementation:
HtmlPage.Window.Invoke("SayHello");
Let me know if you have any issues.
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|