J2ME sends a picture to servlet (error correction)

xiaoxiao2021-04-09  346

Sorry, I sent a picture to the servlet in the J2ME platform. I ignored a detail without the conversion of data types. This will result in the loss of the image pixel, and the picture distortion sent to the server. Now reinstate the code, please forgive me if you bring any inconvenience.

Public synchronized void connchtp () {while (true) {system.out.println ("httpconn wait now"); if ((Midplet.getissending ())) {system.out.println ("Search"); try {con = (HttpConnection) Connector.Open (URL); Con.SetRequestMethod (HTTPConnection.post); Con.SetRequestProperty ("if-modified-since", "29 OCT 1999 19:43:31 GMT"); con.setrEquestProperty (" User-agent, "profile / midp-2.0 configuration / cLDC-1.0"); Con.SetRequestProperty ("Content-Language", "EN-US);

OS = New DataOutputStream ()); int [] rgbarg = new int [100 * 100]; midplet.getimage (). getRGB (rgbarg, 0,100,0,0,100,100); byte [] bytes = INTTOBYTE (RGBARG) Os.write (bytes);

// for (int i = 0; i

Os.flush ();

} catch (exception e) {system.out.println ("conn err"); E.PrintStackTrace ();} finally {if (os! = null) {Try {os.close (); midplet.setissending (False) Midplet.setissend (TRUE);} catch (ooException ooe) {};}}

Midplet.setissending (falple); midplet.setissend (TRUE);} Try {Wait ();} catch (exception e) {system.out.println ("Wait Exception"); E.PrintStackTrace ();}}

}

Public synchronized void wakeup () {notifyAll ();} private bote [] INTTOBYTE (int [] INTS) {byte [] bytes = new byte [INTS.LENGTH * 4]; for (int i = 0; i >> 24); bytes [i * 4 1] = (byte) (0xFF & (INTS [i] >> > 16)); BYTES [i * 4 2] = (byte) (0xFF & (INTS [I] >>> 8); bytes [i * 4 3] = (byte) (0xFF & (INTS [i] >>> 0)); if (i <100) {system.out.Println (INTS [I]);}}

The client, than the last time, a method INTTOBYTE () passed this method, gains an array of BYTE types, sends directly, the server, restores this Byte array into an int array

============================================================================ Private void createiamge (DataInputStream Io, OutputStream Out ) {int width = 100; int Height = 100; int [] RGB = new int [width * height]; try {int [] BYTES = new int [RGB.LENGTH * 4]; // oo (bytes) ; // rgb = bytetoint (bytes); for (int i = 0; i

} Catch (IOException ioe) {ioe.printStackTrace ();} BufferedImage bi = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB); bi.setRGB (0,0,100,100, rgb, 0,100); bi.flush (); // encode: JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam (bi); param.setQuality (1.0f, false); encoder.setJPEGEncodeParam (param); System.out.println ( "yeah"); Try {encoder.encode (bi); ooException ooe {ooe.printstacktrace ();}

}

Private vid bytetoint (int [] bytes, int [] RGB) {for (int i = 0; i

System.out.println (RGB [i]);

}

}

The above is the server-side code, focusing on the readunSignedByte () method. Otherwise it is difficult to restore int types.

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

New Post(0)