Flash8 Bitmap buffer applications: Sticker

Source: Internet
Author: User
Tags integer static class tostring stringbuffer

Personally think this method is much cheaper than using flashcom, is a bit of resources, but the requirements of the environment is very simple. We'll show you a formal application in two days.

  http://220.194.55.60:8080/bitmap/MDT.html

This is my use of Flash8 bitmap buffer to make the bulk paste application.

Completely independent of flashcom, this big sticker is not like the previous, to Flashcommunicationserver to help.
This use of Flash8 bitmap buffer technology, do not need to Flashcommunicationserver server Java program writing really cost my boss's strength Ah!! Two days, but it's worth it, haha. Note: If you want to test, you must have a camera and flash Player 8 to do. (In fact, the camera is not necessary, no camera, you can not see the real effect, but the function can still be achieved, haha)

  Http://220.194.55.60:8080/bitmap/MDT.html

I'll put the JavaBean on, and the JSP file that I accepted.
Look at the JSP first.

<%@ page contenttype= "text/html; charset=gb2312 "language=" java "import=" com.n0rthwood.* "errorpage=" "%>"
<%
Prevent caching
Response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Counter
String click= (String) application.getattribute ("click");
%>
<%
Initializing counters
if (click==null| | Click.equals ("")) {
click= "1";
}
int Tmp=integer.parseint (click);
tmp=tmp+1;
Click= "" +TMP;
Application.setattribute ("click", click);
Receive Picture length width
String widthstr= (String) request.getparameter ("width");
String heightstr= (String) request.getparameter ("height");
if (widthstr==null| | heightstr==null| | Widthstr.equals ("") | | Heightstr.equals ("")) {
Turn to error page
Response.sendredirect ("erro.jsp");
Return
}
%>
<%
Converts a long width from a string to an integral type
int Widthint=integer.parseint (WIDTHSTR);
int Heightint=integer.parseint (HEIGHTSTR);
Receives picture pixels, because the image pixel is an array of behavior units, so you can loop the height so many times to receive all rows.
String[] Pixelcolor=new string[widthint-1];
for (int i=0;ipixelcolor[i]= (String) request.getparameter ("px" +i);
}
try{
Call my JavaBean to write the picture to the hard drive
Com.n0rthwood.JpgTest.JpgTset (Widthint,heightint,pixelcolor);
Turn to the picture that just generated
Response.sendredirect ("temp.jpg");
}catch (Exception e) {
If an error occurs, an error message is displayed
Out.println (E.tostring ());
}
%>
And then the JavaBean.
Package Com.n0rthwood;
Import Java.io.File;
Import Java.io.FileOutputStream;
Import Java.awt.Graphics2D;
Import Java.awt.Graphics;
Import Java.awt.Image;
Import Java.awt.image.BufferedImage;
Import Com.sun.image.codec.jpeg.JPEGCodec;
Import Com.sun.image.codec.jpeg.JPEGImageEncoder;
public class imagesaver{
static method: Parameter meaning: int wide, int high, contains the color information of the string array, here if you don't understand this array, you can go to the address I mentioned in the previous blog, where there is information on how to write Flash files, and all the parameters passed to the server.
public static void Jpgtset (int width,int height,string[] rowcolor) throws exception{
BufferedImage bufimg= New BufferedImage (WIDTH,HEIGHT,BUFFEREDIMAGE.TYPE_INT_RGB);
for (int i=0;iCall the static class below to set the string to an array
String[] Coldot=stringtoarray (Rowcolor[i], ",");
for (int j=0;j<coldot.length;j++) {
int Rgb=integer.parseint (coldot[j],16);
Set color for each pixel
Bufimg.setrgb (J,I,RGB);
}
}
It's time to save
FileOutputStream out=new FileOutputStream ("temp.jpg");
Compress in JPG format
JPEGImageEncoder encoder = Jpegcodec.createjpegencoder (out);
Encoder.encode (BUFIMG);
Out.close ();
}
/* This class converts strings into arrays: For example, you have a string of "a,b,c,d,e,f,g" delimiter is a comma, with this function can get an array of strings: such as s[6], you will find that a is equal to s[0].b is s[1] an analogy.
If you do not know why, see the connection in the first article. */
public static string[] StringToArray (string s, String Sep) {
StringBuffer buf = new StringBuffer (s);
int arraysize = 1;
for (int i = 0; i < buf.length (); i++) {
if (Sep.indexof (Buf.charat (i))!=-1)
arraysize++;
}
string [] elements = new String [arraysize];
int y,z = 0;
if (buf.tostring (). IndexOf (Sep)!=-1) {
while (Buf.length () > 0) {
if (buf.tostring (). IndexOf (Sep)!=-1) {
y = buf.tostring (). indexOf (Sep);
if (y!= buf.tostring (). LastIndexOf (Sep)) {
Elements[z] = buf.tostring (). substring (0, y); z++;
Buf.delete (0, y + 1);
}
else if (buf.tostring (). LastIndexOf (Sep) = y) {
Elements[z] = buf.tostring (). substring (0, buf.tostring (). IndexOf (Sep));
z++;
Buf.delete (0, Buf.tostring (). IndexOf (Sep) + 1);
Elements[z] = buf.tostring (); z++;
Buf.delete (0, Buf.length ());
}
}
}
}
else {Elements[0] = buf.tostring ();}
BUF = null;
return elements;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.