Send pictures to servlet based on J2ME platform

xiaoxiao2021-04-09  358

A few days ago, I saw a friend in question on how to send the picture on the MIDP device to the network through J2ME. I first felt that this should be a problem, so I gotten the Internet and I also turn over the book. So I found a little surprised fact that it seems that all the Tutorials of the MIDP network give an example that a picture from the network reads a picture to the MIDP device, but it really does not have an example of reverse direction. So very curious, I tried to write such a program, and I found two difficulties when I did. Now record the problems encountered in this program for everyone to share.

The first question when writing this program is the generation of the picture object. That is, the IAMGE object is generated in J2ME. There are many people who think that the image object in J2ME and J2SE should be the same, in fact, it is not difficult to find or different places when reading the API. The IAMGE objects of the J2ME are simplified than J2SE. The method of generating pictures is not much change, you can transfer directly from the resource file. You can also generate yourself and put the IAMGE object as a 2-bar buffer. This doesn't have much difference. So where is the difference in this example? Oh ... don't worry, we first analyze what the image sent through the network is? It must be sent through the stream. If it is J2SE, it is simple, directly sending the object stream, you can. But can it be in J2ME? I didn't try it. Then we don't have to send it, change a method, some people will tell me that IAMGE object can be directly converted to a BIT array, don't you send this binary stream? This method is good, but try the IAMGE object has a binary array in J2ME. What should I do? It doesn't matter, or the binary array we get the original array result should be the same. How is the INT array now? This is simple, you can use the RGB array. There is a direct getRGB method in the Image object, but the location of the parameters here and the Javax.Microedition.lcdui.Image.GBData, int Offset, int Scanlength, int X, int y, int width The intangia is the first is the target array, the second is the offset, the third is the length of the scan, the latter two is the starting position, and the last two are the width and height to obtain. The length of the scan is generally greater than or equal to the width of the acquired. After this problem is solved, the following is to send. This should not be a problem. After all, this article has been much more. Then, the servlet is a problem, here I have a * .jpeg file through servlet, when generating this file, there is a second problem, the JPEG file has its own header information, can not be simple when saving Save file. Instead, it is necessary to pass simple encoding. How to do this coding?嘿 ... There is a expansion package set to resolve this issue in the J2SE package. COM.SUN.MAGE.CODEC.JPEG encodes it.

Specific as the following piece code private void createiamge (InputStream Io, OutputStream out) {int width = 100; int Height = 100; int [] RGB = new int [100 * 100]; try {for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-132984.html

New Post(0)