Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ImageBase {}
- JpegImage : ImageBase {}
- TiffImage : ImageBase{}
- var image=ImageBase.GetImageFromDisk(path);
- //some casting to subclass maybe??
- var tiffImage=image as TiffImage;
- tiffImage.Location=new FtpLocation();//not sure if this is a good idea
- tiffImage.Save();
- public void Save()
- {
- // TODO: add any language-specific constructs like "using", etc
- Stream stream = Location.OpenWrite();
- Save(stream);
- stream.Close();
- }
- protected abstract void Save(Stream stream);
- public static ImageBase Load(Location location)
- {
- // TODO: add any language-specific constructs like "using", etc
- Stream stream = location.OpenRead();
- // TODO: wrap in a buffered/seekable stream so we can peek
- // TODO: parse headers and resolve image type
- ImageBase image = ...
- image.Location = location;
- stream.Position = 0; // rewind buffered/seekable stream
- // (don't use Load() since we have already opened the stream)
- image.Load(stream);
- stream.Close();
- return image;
- }
- protected abstract void Load(Stream stream);
- public void Load()
- {
- // TODO: add any language-specific constructs like "using", etc
- Stream stream = Location.OpenRead();
- Load(stream); // don't need to buffer if loading from subclass
- stream.Close();
- }
- public class Image {
- public void load(byte[] imageData);
- public byte[] getImageData();
- }
- public class JpegImage extends Image {
- public void load(byte[] imageData) {
- /* decode image data. */
- }
- public byte[] getImageData() {
- /* encode and return the JPG data. */
- }
- }
- public class Location {
- public Image loadImage(String uri);
- public void saveImage(Image image);
- }
- public class HttpLocation extends Location {
- public Image loadImage(String uri) {
- byte[] = getData(uri);
- if (type == JPEG) {
- return new JpegImage().load(byte);
- } else if (type == PNG) {
- return new PngImage().load(byte);
- }
- }
- public void saveImage(Image image) {
- byte[] imageData = image.getImageData();
- /* upload. */
- }
- }
- Image
- ImageFormat { Save(Image, Stream); Image Load(Stream); }
- JpegFormat : ImageFormat {}
- TiffFormat : ImageFormat {}
Add Comment
Please, Sign In to add comment