Embedding resources (images, sound bits, etc) into a Java project then use those resources

Just put those resources in the source/package structure and use ClassLoader#getResource() or getResourceAsStream() to obtain them as URL or InputStream from the classpath by the full qualified package path. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream input = classLoader.getResourceAsStream(“/image.gif”); // … Or if it is in the same package as the current class, you can also obtain … Read more

WPF – Image ‘is not part of the project or its Build Action is not set to Resource’

Try doing a full rebuild, or delete the build files and then build the file. Visual Studio doesn’t always pick up changes to resources, and it can be a pain to get it recompile. Also try using a full URI as that helped me when I had the same problem. Something like pack://application:,,,/MyAssembly;component/bug.png

@media queries and image swapping [closed]

In the future please add code you’ve tried. if it’s an image tag you can use a class. Hide the second image on page load and show + hide image 1 at a certain screen size like so: HTML <img src=”image.jpg” class=”image1″/> <img src=”image.jpg” class=”image2″/> CSS .image2{ display: none; } @media only screen and (max-width: … Read more

How to correctly use the Image Source property with Xamarin.Forms?

You shouldn’t reference the path because the source property is cross-platform and since every platform has a different folder for assets like images, you only need to specify the filename and extension. The Image class knows where to look to find the file. Image files can be added to each application project and referenced from … Read more

WPF – converting Bitmap to ImageSource

For others, this works: //If you get ‘dllimport unknown’-, then add ‘using System.Runtime.InteropServices;’ [DllImport(“gdi32.dll”, EntryPoint = “DeleteObject”)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteObject([In] IntPtr hObject); public ImageSource ImageSourceFromBitmap(Bitmap bmp) { var handle = bmp.GetHbitmap(); try { return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } finally { DeleteObject(handle); } }

BitmapImage to byte[]

To convert to a byte[] you can use a MemoryStream: byte[] data; JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmapImage)); using(MemoryStream ms = new MemoryStream()) { encoder.Save(ms); data = ms.ToArray(); } Instead of the JpegBitmapEncoder you can use whatever BitmapEncoder you like as casperOne said. If you are using MS SQL you could also use a image-Column … Read more