java - Use ImageIO.read for class extending BufferedImage -


(what people have against hello?)

i have class extends bufferedimage:

public class namedimage extends bufferedimage{     string name;     public namedimage(int width, int height, int imagetype) {         super(width, height, imagetype);     }     public void setname(string text){         name = text;     } } 

before had this, got images with:

image image = imageio.read(res); 

now, want translate namedimage, following tries don't work:

namedimage image = imageio.read(res); namedimage image = (namedimage) imageio.read(res); 

how can achieve want do? why can't cast buffered image class, extends custom class?

(what people have against thank you?)

here's possibility, if want imageio use specific subclass. however, if want give name, i'd use @andrewthompsons suggestion map<string, bufferedimage>, because it's less verbose.

imageinputstream stream = imageio.createimageinputstream(res); iterator<imagereader> readers = imageio.getimagereaders(stream);  if (readers.hasnext()) {     imagereader reader = readers.next();     reader.setinput(reader);      int w = reader.getwidth(0);     int h = reader.getheight(0);      imagereadparam param = reader.getdefaultreadparam();      namedimage image = new namedimage(w, h, bufferedimage.type_int_argb);     param.setdestination(image);      /*image = (namedimage)*/ reader.read(0, param); } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -