ResourceImage.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package me.hammerle.supersnuvi.javafx;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. public class ResourceImage extends Image
  6. {
  7. private javafx.scene.image.Image fxImage;
  8. public ResourceImage()
  9. {
  10. fxImage = null;
  11. }
  12. public void load(String path)
  13. {
  14. File f = new File(path);
  15. try
  16. {
  17. fxImage = new javafx.scene.image.Image(new FileInputStream(f));
  18. }
  19. catch(FileNotFoundException ex)
  20. {
  21. System.err.println("can't load image from '" + f.getPath() + "'");
  22. }
  23. }
  24. public void load(String path, double rw, double rh)
  25. {
  26. File f = new File(path);
  27. try
  28. {
  29. fxImage = new javafx.scene.image.Image(new FileInputStream(f), rw, rh, true, false);
  30. }
  31. catch(FileNotFoundException ex)
  32. {
  33. System.err.println("can't load image from '" + f.getPath() + "'");
  34. }
  35. }
  36. @Override
  37. protected javafx.scene.image.Image getImage()
  38. {
  39. return fxImage;
  40. }
  41. @Override
  42. public double getWidth()
  43. {
  44. return fxImage == null ? 0 : fxImage.getWidth();
  45. }
  46. @Override
  47. public double getHeight()
  48. {
  49. return fxImage == null ? 0 : fxImage.getHeight();
  50. }
  51. }