I am working on a wpf application. I am having one image, i have put some more images on it, with lowered transparency(sort of watermarking you can say). Is their any way to save the present look of the two or three images(watermarked images) into one new image??
You can use RenderTargetBitmap to render Visuals, to render your stack of images you should place them in some wrapping control (if only temporarily). This article might be helpful.
Related
I'm making a Windows Store Application that display really big images in a ScrollViewer.
The source image is very big and the rendering with the Image is bad (because the Image is really smaller than the source image, so the scaling make the result ugly).
I want to use direct2D to have a better rendering (the project is in c#).
I'm really new to this, so I don't really know how to do... I've found those links that seems interesting:
XAML SurfaceImageSource DirectX interop sample (Windows 8.1)
How to Draw a BitmapSource Using Direct2D
The SurfaceImageSource sample is good, but only shows how to render sharpes...
And I don't know how to use the second links with SurfaceImageSource.
Is there anybody who have a good example about this? Thanks!
I think you can try VirtualSurfaceImageSource.It can render large image.
Learn more:
http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx
I have a desktop app build using .net. I want it to support multilanguages. I am able to do that using resources. Issue is what should I do for images which have text? Should I include all images for separate languages? If so then this will make it difficult and also will increase its size.
I just read that in Android there is "9 patch image", isn't there something similar?
I wish to add background image, and write text on top of that. This background image should resize without change in quality of the image automatically to the size of text in that language.
I couldn't think of any way to avoid separate images with WinForms. WPF, no problem. Web app, no problem. I played around with both text and image on a Button control, but that does not scale fully. I tried using a label over a PIctureBox, but it is impossible to achieve transparency with a Label control. I also tried this using a WebBrowser control--such a thing could possibly work, but would take some further research and would probably change your deployment dramatically (since you would need to make the localization available from some http server).
So I think there is no easy way to do this--I could find nothing easier than maintaining the images separately.
In one of my projects, i had text displayed on top of images. Since the site was multilingual, so no text was part of the images. Instead text was displayed on top of the images, using css properties for absolute position. This had to be tested in all browsers, with multiple languages, as the text size varies in each language, this might break the UI. so enough space has to be provided for text considering all supported languages
I know it's recommended to convert images to XAML as they become blurred when changing the dpi.
What about standard ICO files which actually are really BMP files?
I need to use these in a toolbar. Do I need to convert all to XAML?
Is there a better way?
What about a similar feature in HTML called sprites where it's one big image but you get items via positions?
Essencially you work with static images when no scaling is needed, and you work with Vector Images when you want to perform all sorts of scaling. This is the rule of thumb for most WPF and Silverlight applications.
However you can't directly convert a static image to a Vector Image (what you call XAML), and most times it will require a designer to do some work on the Vector Image.
Working with vector images makes the rendering process heavier, the more vectors, the slower the rendering pass. It also makes it slower to instanciate a particular Visual Tree, when you add it to something already on screen. This can be overcome if you call RenderToBitmap and cache the sizes of the Vector Images you want to use, but this requires aditional custom code.
Working with static images allows for much faster renders. However upsizing will cause pixelization and downsizing may cause artifacts on the image. When you work with static images PNG is considered to be the prefered format, you have full control over the compression, you have alpha key and it's an indexed format which makes it fairly small in size.
I always convert all images to XAML where it's possible. I think it's good rule.
A winform control for displaying a list of images is currently implemented with a flowlayoutpanel and a collection of pictureboxes. But even at thumbnail scale (64x64) when we when start to approach 1000+ images we get OutOfMemory exceptions - our actual problem lies from the thumbnail generation part and the creation of the Image object.
I haven't been able to find any strategies from the existing image viewing examples on the net regarding a large number of images so does anybody have any links or strategies for solving this problem of displaying a list of 1000+ images?
As a starting point we really only need these image objects around when the thumbnail's picture box is in view. Then we would only have 10 image objects created but is there a smarter way of doing this other than loading and destroying image objects?
Thanks,
Edward
You should display only one screen of images at a time.
When the user drags the scrollbar, destroy those images and load new ones.
WPF handles this in a great way. If you have turned on Virtualization, the ListBox will create only the control that are visible to the screen.
In your case, keep reference to the images in a list. Put a pictureBox, and based on the Scrollbar, change the image on the pictureBox.
I have a winforms ImageList which contains 200 256x256 images.
When I add the images, 1 by one, half of the programs time spent on the Add method according to ANTS .NET profiler.
So the program takes 10 secs to launch and 5 is spent there. That is very slow in my opinion.
I implemented the same thing using ImageList.Images.AddRange. The result did not change.
Does anyone know any alternatives or optimizations to solve this? Is the WPF ImageList any faster? Is there a faster winforms ImageList?
EDIT:
foreach (string imageFile in images)
{
imageList.Images.Add(Image.FromFile(imageFile)); // takes pretty much all of program's execution time.
}
Have a look at the album and list views in PhotoSuru, one of Microsoft's WPF sample applications. They have a couple different thumbnail view screens that load pretty quickly (all the images are loaded asynchronously, and only the images necessary are loaded). And there's full source code to get you started if it's what you are looking for.
It not precisely like Picasa (they decided only to show full rows of photos instead of a partially covered row like Picasa), but by implementing your own virtualizing IScrollInfo panel (reasonably straightforward, and Ben Constable has a great series of posts on it), you should be able to get the performance you're looking for and the behaviour you want.
A final note: You might be doing this already (are your images stored as 256x256 pixel images?), but whenever you're trying to display image thumbnails, you'll want to avoid loading the full image. Reading 2 MB+ image files off of the disk just to render an entire screenful of 256x256 pixel thumbnails always has a bigger performance hit than reading an appropriately sized small thumbnail image instead. If you can, cache the thumbnails somewhere (like Windows and Picasa do), or at the very least, try to use the embedded thumbnails in any JPEG files you encounter.
Are you using a ListView for the UI part using that ImageList?
The general solution to these kind of problems is to only load some of the images, because only some of them are shown at a time, and then load the other as needed. ListView has a VirtualMode property for this kind of scenarios.
Loading and adding 200 images at once may be too much to do, you could load the first shown images and then use a background thread to load the others. Have a look at how Win7 display images, it shows some placeholder when you scroll and then, when the image is loaded it shows the real picture. Be warned that this is not a simple thing to do.
try my code here to scale-down your image and make a thumbnail out of it.
Yes it is. Load images to List<Image>. Then call ImageList.Images.AddRange(list).
List<Image> list = new List<Image>();
foreach (string imageFile in images)
{
list.Add(Image.FromFile(imageFile));
}
imageList.Images.AddRange(list.ToArray());