1 26 27 package it.stefanochizzolini.clown.documents.contents.entities; 28 29 import it.stefanochizzolini.clown.bytes.IInputStream; 30 31 34 public abstract class Image 35 extends Entity 36 { 37 public static Image get( 42 IInputStream stream 43 ) 44 { 45 try 46 { 47 byte[] formatMarkerBytes = new byte[2]; 49 stream.read(formatMarkerBytes); 50 51 if(formatMarkerBytes[0] == (byte)0xFF 53 && formatMarkerBytes[1] == (byte)0xD8) 57 {return new JpegImage(stream);} 58 else {return null;} 60 } 61 catch(Exception e) 62 {throw new RuntimeException (e);} 63 } 64 68 private int bitsPerComponent; 71 private int height; 72 private int width; 73 74 private IInputStream stream; 75 77 protected Image( 79 IInputStream stream 80 ) 81 {this.stream = stream;} 82 84 89 public int getBitsPerComponent( 90 ) 91 {return bitsPerComponent;} 92 93 96 public int getHeight( 97 ) 98 {return height;} 99 100 103 public int getWidth( 104 ) 105 {return width;} 106 108 112 protected void setBitsPerComponent( 113 int value 114 ) 115 {bitsPerComponent = value;} 116 117 120 protected void setHeight( 121 int value 122 ) 123 {height = value;} 124 125 128 protected void setWidth( 129 int value 130 ) 131 {width = value;} 132 133 136 protected IInputStream getStream( 137 ) 138 {return stream;} 139 } | Popular Tags |