December 2001
"Discussion on the Method of Inlined Image Resources" (Liluqun@263.net)) Shandong University of Science and Technology Computing Center) One article: "In the Java application, you can dynamically call the displayed image file (such as: * .gif, *. jpg), but it is not enough to use the image resource called directly to use the Java application, must be stored on the hard disk or network in the form of a file. When the application is sent to the user, the user Various image editing software can be easily used, which will not be tampered with the image file resource corresponding to the program. Imagine if these image files are important copyright signs, then the consequences are definitely the application developers don't want to see. Therefore, it is necessary to use some measures to protect these image files. "The authors used the image constructor: image img = Toolkit.getDefaultToolkit (). CreateImage (byte [] map);
Simply convert the image file into a zygotype type type of the Java source program, embedded, and then configure the IMG object to implement the embedded image resources in the source program to achieve the protection image file.
This is a good, feasible method. What I want to say here is another way. Use the Javax.swing.Imageicon class. The ImageICON class is a sequentially-sequence class. We can use, ObjectInputStream, ObjectOutputStream class. Save the image file with the WriteObject (Object Obj) method to a file to achieve the image file.
Main program code:
Imageicon icon = new imageicon ("copy.jpg");
ObjectOutputStream out = new ObjectOutputStream (New FileoutputStream ("image.img");
Out.writeObject (icon);
Then, use the readObject () method to image into imageicon.
Main program code:
ObjectInputStream out = new ObjectInputStream (New FileInputStream ("Image.img");
Icon = (imageicon) Out.readObject ();
The image can be displayed with other objects. Such as: public void Paint (Graphics G) {g.drawimage (icon.getimage (), 0, 0, 350, 263, this)
In addition, you can use a similar approach to use the ZIP class to compress file compression using the ZIP class. The file can make the file more confidential.
Main program code:
Imageicon icon = new imageicon ("copy.jpg");
ObjectOutputStream out = new ObjectOutputStream (New FileoutputStream (New FileoutputStream ("Image.img")))
Out.writeObject (icon);
Unzip code: ObjectInputStream IN = New ObjectInputStream (New FileInputStream (New FileInputStream ("Image.img")); icon = (imageicon) Out.readObject ();