Public voidReplaceimagecolor (String file, color srccolor, color targetcolor)throwsioexception{URL http; if(File.trim (). StartsWith ("https") ) {http=NewURL (file); Httpsurlconnection Conn=(httpsurlconnection) http.openconnection (); Conn.setrequestmethod ("GET"); }Else if(File.trim (). StartsWith ("http") ) {http=NewURL (file); HttpURLConnection Conn=(HttpURLConnection) http.openconnection (); Conn.setrequestmethod ("GET"); }Else{http=Newfile. Touri (). Tourl (); } bufferedimage Bi=Imageio.read (Http.openstream ()); for(inti = 0; I < bi.getwidth (); i++) { for(intj = 0; J < Bi.getheight (); J + +) {System.out.println (Bi.getrgb (i, j)); if(Srccolor.getrgb () = =Bi.getrgb (i, J)) {System.out.println (i+ "," +j+ "From:" +srccolor.getrgb () + "to" +Targetcolor.getrgb ()); Bi.setrgb (i, J, Targetcolor.getrgb ()); } }} Iterator<ImageWriter> it = imageio.getimagewritersbyformatname ("PNG"); ImageWriter writer=It.next (); File F=NewFile ("C://test02.png"); Imageoutputstream iOS=Imageio.createimageoutputstream (f); Writer.setoutput (iOS); Writer.write (BI); Bi.flush (); Ios.flush (); Ios.close (); } Public voidCreateImage (intWidthintHeightthrowsioexception{bufferedimage Bi=Newbufferedimage (width, height, bufferedimage.type_4byte_abgr); Graphics2D graphic=Bi.creategraphics (); Graphic.setcolor (NewColor (0.2f,0.3f,0.4f,0.4f)); Graphic.fillrect (0, 0, width, height); for(inti = 0; I < width; i++) { for(intj = 0; J < height; J + +) { //Result[i][j] = Bi.getrgb (i, j) & 0xFFFFFF;System.out.println (Bi.getrgb (i, j)); //Bi.setrgb (i, J, 0xFFFFFF);}} Iterator<ImageWriter> it = imageio.getimagewritersbyformatname ("PNG"); ImageWriter writer=It.next (); File F=NewFile ("C://test02.png"); Imageoutputstream iOS=Imageio.createimageoutputstream (f); Writer.setoutput (iOS); Writer.write (BI); }
Java reads pictures and modifies pixels to create pictures