Jump to content
  • Advertisement
Sign in to follow this  
Goguis

Creating image from canvas?

This topic is 4112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys. A friend told me once that i could create and image based on a canvas that has already being draw with other images. I mean, is this posible? to create an image like a SS from an existing canvas? THanks

Share this post


Link to post
Share on other sites
Advertisement
I got it. I found this link: http://www.java2s.com/Code/Java/J2ME/Drawmutableimageonacanvas.htm

The sad thing is i cant get the rgb values... so i cant create an int array for the colores and make some pixels transparent... or can i?

Cya

Share this post


Link to post
Share on other sites
mmmh, strange. I wrote the code (similar), and i cant make this line to work: Graphics graphics = im.getGraphics(); The difference is that i defined Graphics graphics out side...

What can i do?

Share this post


Link to post
Share on other sites
here's some source... i cant past it all because its 3000 lines long.
Of course there are some public void "veryimportantemethod"() missing.... i just didnt put them :)

public class BaseCanvasA extends GameCanvas implements Runnable
{
int okNormalAnchoMitad=0;
int valorSoporteX=0;
int valorSoporteY=0;
int i=0;
int j=0;
//Objetos
Graphics g = getGraphics();
Graphics imA;
Graphics imR;
public void createMarcoAzul(int ancho, int alto, int marco, Image imagen, int margenSup)
{
try
{

imA = marcoFinalAzul.getGraphics();//THIS IS THE ERROR
}catch(Exception e)
{
System.out.println("No funciono el getGraphics");
}

imA.setColor(255,255,255);
imA.fillRect(0,0,anchoPantalla,altoPantalla);
acompa=(anchoPantalla/resEntrada)+6;
acompados=(altoPantalla/resEntrada)+6;
valorSoporteX=(((middleScreenX/resEntrada)+1)*resEntrada);
valorSoporteY=(((middleScreenY/resEntrada)+1)*resEntrada);
for(i = 0 ; i < acompa ; i++)
{
for(j = 0 ; j < acompados ; j++)
{
imA.drawImage(fondoCu, margenX+resEntrada*i-valorSoporteX, margenY+resEntrada*j-valorSoporteY, 0);
}
}
i=0;j=0;
for(i=0; i<=ancho-marco;i+=marco)
{
imA.setClip(middleScreenX-ancho/2+i,middleScreenY-alto/2-marco-margenSup,marco,marco);//4
imA.drawImage(imagen,middleScreenX-ancho/2-marco+i-2,middleScreenY-alto/2-marco-margenSup,0);
imA.setClip(middleScreenX-ancho/2+i,middleScreenY+alto/2-margenSup-1,marco,marco);//4
imA.drawImage(imagen,middleScreenX-ancho/2-marco+i-2,middleScreenY+alto/2-margenSup-1+marco,Graphics.BOTTOM|Graphics.LEFT);
}
for(j=0; j<=alto-marco;j+=marco)
{
imA.setClip(middleScreenX-ancho/2-marco,middleScreenY-alto/2+j-margenSup,marco,marco);
imA.drawImage(imagen,middleScreenX-ancho/2-marco,middleScreenY-alto/2+j-marco-2-margenSup,0);
imA.setClip(middleScreenX+ancho/2,middleScreenY-alto/2+j-margenSup,marco,marco);
imA.drawImage(imagen,middleScreenX+ancho/2+marco,middleScreenY-alto/2+j-marco-2-margenSup,Graphics.TOP|Graphics.RIGHT);
}
//arriba izquierda
imA.setClip(middleScreenX-ancho/2-marco,middleScreenY-alto/2-marco-margenSup,marco+marco,marco+marco);
imA.drawImage(imagen,middleScreenX-ancho/2-marco,middleScreenY-alto/2-marco-margenSup,0);
//arriba derecha
imA.setClip(middleScreenX+ancho/2-marco,middleScreenY-alto/2-marco-margenSup,marco+marco,marco+marco);
imA.drawImage(imagen,middleScreenX+ancho/2+marco,middleScreenY-alto/2-marco-margenSup,Graphics.TOP|Graphics.RIGHT);
//abajo a la izquierda
imA.setClip(middleScreenX-ancho/2-marco,middleScreenY+alto/2-marco-margenSup+1,marco+marco,marco+marco);
imA.drawImage(imagen,middleScreenX-ancho/2-marco,middleScreenY+alto/2+marco-margenSup-1,Graphics.BOTTOM|Graphics.LEFT);
//abajo a la derecha
imA.setClip(middleScreenX+ancho/2-marco,middleScreenY+alto/2-marco-margenSup,marco+marco,marco+marco);
imA.drawImage(imagen,middleScreenX+ancho/2+marco,middleScreenY+alto/2+marco-margenSup-1,Graphics.BOTTOM|Graphics.RIGHT);
imA.setClip(0,0,anchoPantalla,altoPantalla);


}
public void run()
{
}
}



Share this post


Link to post
Share on other sites
What is the actual problem? Does it throw an exception? Does it just not display to the screen?

Is marcoFinalAzul a mutable or immutable image? (What CreateImage() method is used to create it?)

When you want the image to display do you call g.drawImage(marcoFinalAzul,...); ?

Share this post


Link to post
Share on other sites
Quote:
Original post by trojanman
What is the actual problem? Does it throw an exception? Does it just not display to the screen?


It Throws an exception.

Quote:
Original post by trojanman
Is marcoFinalAzul a mutable or immutable image? (What CreateImage() method is used to create it?)


i used Image.createImage(int width, in height); so yes, its a mutable image

Quote:
Original post by trojanman
When you want the image to display do you call g.drawImage(marcoFinalAzul,...); ?


yes, i call g.draw....

Share this post


Link to post
Share on other sites
Quote:
Original post by Goguis
Quote:
Original post by trojanman
What is the actual problem? Does it throw an exception? Does it just not display to the screen?


It Throws an exception.



What exception does it throw (you can get this by printing e.getMessage(), e.printStackTrace(), or e.toString())? Sorry, I should have asked this when I asked if it threw an exception. Have you looked at the MIDP docs regarding Image.createImage() and Image.getGraphics() as to a possible cause (based on the exception thrown?)

According to the docs - if you get "IllegalStateException" when you make this call the image you are trying to get the graphics from is an immutable image. Also, if you get a NullPointerException check and see if the image you are getting the graphics from has been created.

If you'd like some more help or have other questions you can find me on #gamedev pretty often.

Share this post


Link to post
Share on other sites
it throws: java.lang.NullPointerException

mmmmh, i haven't been able to find an answer to why it can throw nullpointerexception. The strange thing is that the image IS being created... also in a try/catch and it doesn't throw any issues.

Share this post


Link to post
Share on other sites
Quote:
Original post by Goguis
it throws: java.lang.NullPointerException

mmmmh, i haven't been able to find an answer to why it can throw nullpointerexception


Check to see if marcoFinalAzul has been created (and is not null) before you call marcoFinalAzul.getGraphics().

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!