creating an image, saving to memory card and MMS-*** it !
Right, as you can read from the title i am trying something a little adventurous but I know it is possible.
First of all this is my thinking:
1. Create a line graph plot using Graphics class upon Canvas
2. Create an image from this drawing and make it immutable
3. Save this image to memory stick on mobile phone (sony ericsson W800i) as LineGraph.png
4. Create an MMS from this image and send it to another mobile phone by giving user a textfield to enter phone number
Below i am going to give simplified snippets of my code and people can please point out erroneous areas, as it seems to go to the MMS form with textfield without catching exceptions or notifying the user.
Commented Numbers refer to above.
// 1. Create a line graph using drawLine()/drawString methods, translated to botton right corner to make things easier
publicvoid paint(Graphics g)
{
g.setColor(0xffffff);
g.translate(45,140);
g.fillRect(0,0, Cwidth, Cheight);
g.setColor(0);
g.setStrokeStyle(Graphics.SOLID);
g.drawLine(0,0, getWidth(), 0);
g.drawLine(0,0,0, -getHeight);
// Plotting of data points upon the linegraph, done iterating through data arrays and calling upon drawLine
// method each time in a dot-to-dot manner
for(int i=0; i<NumDataPoints; i++)
{
if(i == 0)// if i==0 then it means it draws the inital line, needed to avoid loophole
g.drawLine((int)XScaledArray[i], -(int)YScaledArray[i], (int)XScaledArray[i], -(int)YScaledArray[i]);
else
{
g.drawLine((int)XScaledArray[i-1], -(int)YScaledArray[i-1], (int)XScaledArray[i], -(int)YScaledArray[i]);
g.drawString("x", (int)XScaledArray[i], -(int)YScaledArray[i]+6, Graphics.HCENTER | Graphics.BOTTOM);
}
}
//Create a mutable image
LineGImage = Image.createImage(Cwidth, Cheight);
// 2. Now require to create an immutable image to save into file
public Image getImage()
{
Image img = LineGImage.createImage(LineGImage);
return img;
}
// 3. Save this image to file on the Memory Stick
publicvoid createImageFile(Image img)
{
try{
byte[] bImage =null;
FileConnection fileCon = (FileConnection)Connector.open("file///Memory Stick/BluePlot1.png");// also tried MemoryStick spelling, still doesnt save
fileCon.create();
OutputStream out = fileCon.openOutputStream();
img.createImage(bImage, 0, bImage.length);
out.write(bImage);
bSaved =true;
do_alert("Line Graph saved as Image !", 3000);
fileCon.close();
out.close();
}catch(IOException e)
{
do_alert("FileCreation error! : " +e.getMessage(), 4000);
}
}
// 4. MMS code will simply retrieve the location of the line graph .png file and send it as a MultiPart message
What is a definite in this program is the linegraph works fine, all i want to do is create an image file (.png) from that and save it to memorystick and send it as MMS.
Any help would be appreciated.>

