graphics - java drawImage turns complete black -


i'm pasting plenty of face images (face_50xx.png) 1 big canvas (faces.png) using drawimage(),

but every face turns whole black.

here source code:

import java.io.*; import javax.imageio.imageio; import java.awt.*; import java.awt.image.bufferedimage; import java.awt.color;   public class maa{  static bufferedimage in; static bufferedimage out;  public static void main(string[] args) {     string = "face_";     string b = "png";     int j = 0;      try{         in = imageio.read(new file(a + 5001 + "." + b));     }     catch(java.io.ioexception e){     }         out = new bufferedimage(1920, 14592, in.gettype());       for(int = 1; < 760; i++){         string num;         j = + 5000;         num = integer.tostring(j);         try{             in = imageio.read(new file("face_" + num + "." + "png"));             graphics g = in.getgraphics();             g.drawimage(out, (i%10)*192, (i/10)*192, null);          }         catch(java.io.ioexception e){             continue;         }     }     try{         imageio.write(out,"png",new file("faces." + b));     }     catch(java.io.ioexception e){      } }   } 

please teach me what's problem. thanks.

  • you doing absolutely nothing out image, , when write file, blank.
  • you appear drawing on wrong image. want graphics object, g, out image, , draw in images onto out.
  • you should never ignore exceptions doing. @ least print out stack trace:

e.g.,

catch(ioexception e) {   e.printstacktrace(); } 

the basic structure of program should be:

create out image out's graphics object, g loop through of `in` images   draw each in image onto out using out's graphics context, g end loop dispose of g write out image file 

edit: state in comment,

graphics g = in.getgraphics(); command transporting in image g, isn't it?

no, you've got things backwards. think of graphics object, g, pen allows draw onto image obtained from. graphics object, g, in image allows me draw on in image.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -