I am generating tiles from very large images to use with leaflet. I have a working solution that uses System.Drawing.Bitmap and loads the image from file. I already have the image in memory as a BitmapImage however, and would like to reuse it for memory purposes since these images can be very large. But I can not find a good way of doing this with BitmapImage.
What I basically need is something equivalent of
GraphicsHandle.DrawImage(sourceImage, destinationRect, sourceRect, GraphicsUnit.Pixel);
I need to crop and resize a part of the image, and draw this onto another image in a specified location and then save this to file. What is the best way of doing this using BitmapImage?
Related
what I'm trying to do is using an let say pre-loaded image within Emgu.CV.Mat. It offers an constructor where its possible to specify a filename. But my image is already loaded (and manipulated) within the code, therefore it makes no sense to save the file here just to load it again.
I'm working within a WPF Environment and therefor have my image currently as a WriteableBitmap. Furthermore I found couple of hints (e.g. here) how to convert an Mat to WriteableBitmap. But what I'm looking for is the other way round, using a WriteableBitmap in order to Emgu.CV stuff with it.
According to Emgu CV 2.x it was possible to use a Bitmap but it seams that this feature was removed in Emgu CV 3.x.
Any ideas how to do it in Emgu CV Version 3?
I have been experimenting in this area for a work related application. To effectively use a WriteableBitmap with a Mat or an Image<,> you need access to the raw pixels.
Because I have images coming from hardware as well as from creating a RenderTargetBitmap what I found works for me is to allocate a buffer using HGlobalAlloc that is the proper size and use RenderTargetBitmap.CopyPixels() to move the data to this buffer. I also create an Image using an IntPtr to this data. Once I am done with my manipulations I use a WiteableBitmap.WritePixels() to put the image back into the WriteableBitmap.
Here is also a solution from Emgu: BitmapSourceConverter
Doug
We have a system in which we have big plan images loading in multiscale deepzoom images like an image gallery.Images are usually of very high resolutions.
Users have the ability to draw shapes ect on selected deepzoom image.We are using a canves on deepzoom image and save all overlay shapes drwan along with their logical poistion in db.thus the drawn shapes auto sets their position as user pans in or pans out.
We need an automated solution so we can take the printout of all the plan images along with all overlay work done on each deepzoom image.
Currently we are doing this one by one i.e we use Grid,Multistage,Canvas.We load image in Multiscale image,then draw Canves then we use following code to same them in jpeg from Grid(ContentGrid)
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.Filter = "JPG Files (*.jpg|*.jpg|*.jpeg|*.jpeg)";
saveDlg.DefaultExt = ".jpg";
if ((bool)saveDlg.ShowDialog())
{
using (Stream fs = saveDlg.OpenFile())
{
SaveToFile(new WriteableBitmap(ContentGrid, null), fs);
}
}
But this solution does not work properly.This throws memory issues when deepzoom image is big one.
We want something like this.For all plans images in gallery we need to loop and programatically convert to jpeg along with canves etc and then save to Amazon s3 by program.An automation will pick all the jpegs and make a single pdf for all those.
or an automated solution.
Please suggest.
For the images in my application, I have been setting the source property of my image to a JPEG file on disk but, as part of my next iteration, I want to test keeping them in memory for speed.
How do I tell the WPF Image control to get its information from an in-memory source rather than from a file?
Have a look at InteropBitmap and WriteableBitmap, two classes that inherit from BitmapSource that allow you to supply the pixels of the image from an array.
To create an InteropBitmap you use methods on the Imaging class like Imaging.CreateBitmapSourceFromMemorySection.
I'm developing a WinForms c# 3.0 application. Our designer created quite a lot of .ico files containing all the needed art. The choice of .ico was made because quite often, the same image is needed in several places in different dimensions.
Now, it seems .ico files are really annoying to use in visual studio. The only way to use those images seems to be through images list (which aren't supported by all controls).
Compared to other resources, you can't write this :
foo.Image = global::RFQHUB.RFQHUBClient.Properties.Resources.foo; // Cannot implicitly convert type 'System.Drawing.Icon' to 'System.Drawing.Image'
Here are the options I'm considering :
create ImageLists of all possible sizes referencing all my icons in my main window. Link these ImageLists from other windows and find a way to export Image objects from the ImageList when I can't use it directly ; since ImageList contains a Draw() method, this should probably be possible.
convert all the x.ico I've got in several x16.gif ...x48.gif, and use those through resources.
I'd be interested to know if some people have been successfully using .ico resources in a Winform application. In so, how did you set up things ?
ICO isn't quite an obsolete format, but it's close. It's still useful for your application icon, but for almost everything else, it's better to use an ImageList for each size that you need. And it's much faster to populate an ImageList from a bitmap that contains multiple images layed out in a grid.
You also want to use an Alpha channel transparency in your bitmaps to get the best result, so storing them as .PNG files in your resources is the best way to go, since PNG supports an alpha channel. ICO and GIF files support only single bit for transparency - every pixel is either fully opaque or fully transparent. An 8 bit alpha channel for transparency looks much nicer.
If you can send your artist back to the drawing board then you should do so, and have him/her do full anti-aliased images with alpha. If you can't, then I suggest that you write a small program to convert all of your icon files into bitmaps suitable for loading into ImageLists.
Convert the images into PNG. Point. Whoever decided to use .ico files to start with should get talked to in private - the argument holds no ground.
I am using ImageTool's PNG encoder to create an image.
I have a Grid that contains multiple TextBlocks, each TextBlock contains dynamic text.
When I create a WriteableBitmap from the grid containing the TextBlocks, I then use ImageTool's encoder to convert the WriteableBitmap to a PNG image.
All works well, however, when I view the PNG image (am saving the file to the hard drive for testing purposes) - the text looks slightly blurred. Is this an issue with the encoder or the WriteableBitmap class? And - has anyone experienced this before and are there workarounds?
Thanks.
I'm a part of ImageTool project but I'm playing as a tester since I'm using this library in one of my project... If you can create a sample then you can probably show us so that we can test in our machine.
You can also try with Joe Stegman's encoder or fJCore JPEG encoder.