Let say I have application menus in a database with their icon images (binary data). I extract those menus with the icons being byte[] type. However if there's no icon set, then I would like to use default icon which comes not from database, but from xap (inside Resources folder). To display icons coming from database I use IConverter (byte[] to image), which is based on the code of the following question:
Silverlight 4.0: How to convert byte[] to image?
To be able to use my byte[]-to-image IConverter, I would also like to convert my default icon to byte[], which comes from xap. How I can do that? The following question suggested to use WriteableBitmap class, but I don't know how to create WriteableBitMap from the xap source:
Silverlight: image to byte[]
I may be miss understanding the question here (perhaps more details about your converter are required here), but if you converter class just returns an image based on its bytes, cant you just test for null bytes from the DB, then return your default image?
public class MyConveter : IConverter {
public Image ConvertImage(byte[] bytes) {
if (bytes == null) return GetDefaultImage();
else return ConverterBytesToImage(bytes);
}
}
this way you simply return an image as the method declaration, and the implementation handles the null bytes case.
Is this on the right track?
As your default icon is a resource, you can open it as a ResourceStream and just read it in as bytes.
Would that meet your requirements?
Related
My app has an animated Image set as icon of a Label instance.
Since Version 3.3 the image is not painted any more. However the animated() methos ist still called and returns true.
Is that caused by "performance improvements"?
What can I do about it?
Ok, I think I found the correct measure:
Now my animated image class overrides com.codename1.ui.Image.getImage() and returns the result of getImage() of an Image instance created using com.codename1.ui.Image.createImage(int, int, int) which I previously only used in my method which overrode com.codename1.ui.Image.drawImage(Graphics, Object, int, int).
Now apparently drawImage() isn't called anymore, but the getImage() instead.
Are you implementing your own custom subclass of image that relies on draw image?
If so you need to override requiresDrawImage in that Image subclass as such to disable the performance optimizations in drawing this image:
#Override
public boolean requiresDrawImage() {
return true;
}
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?
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 want to implement previews/thumbnails in my project, therefor i need the graphical output of a control as bitmap. I have a third party control which loads documents and displays them. Is it possible to fetch the output of an control and store it in a bitmap object without adding it to the UI? And If how?
Edit: I probably should said that before, but i don't know if that's important. The ThirdParty Control is an OCX(ActiveX control).
in a Form do:
Bitmap myBitmap = new Bitmap(button1.Width, button1.Height);
// button1.Draw..., not 'this.Draw...'!
button1.DrawToBitmap(myBitmap, button1.DisplayRectangle);
myBitmap.Save(#"C:\test.bmp");
How can I get information about the source image of a WPF <Image> element?
My <Image> element has its Source bound to an ImageSource property, which changes frequently. In my code behind, I need to be able to access the actual width of the current source image file (in regular pixels), for mathematical purposes. My application will perform image operations on the image file, so this information is necessary.
Any help is appreciated.
I think this may work for you:
BitmapSource sourceData = image.Source as BitmapSource;
int width = sourceData.PixelWidth;
int height = sourceData.PixelHeight;