Problem with canvas

All your problems with Audio, Video and Images.

Problem with canvas

Postby matt46 » Sat Nov 29, 2008 8:29 pm

Hi everybody!

I'm tring to make my first program with the android sdk.

I've created a canva, with a colored bitmap set as background.
I want to add another bitmap on the first bitmap, as if it was a stamp for example.

The second bitmap will be smaller than the first one and will have to appear on the top left corner of the screen.

But I have a little, problem, I don't know how to display the canva on the screen. The application stop with an error.

Here's my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. package test.test;
  5.  
  6.  
  7.  
  8. import javax.microedition.khronos.opengles.GL;
  9.  
  10.  
  11.  
  12. import android.app.Activity;
  13.  
  14. import android.graphics.Bitmap;
  15.  
  16. import android.graphics.BitmapFactory;
  17.  
  18. import android.graphics.Canvas;
  19.  
  20. import android.graphics.Paint;
  21.  
  22. import android.os.Bundle;
  23.  
  24.  
  25.  
  26. public class test extends Activity implements GL{
  27.  
  28.     /** Called when the activity is first created. */
  29.  
  30.     @Override
  31.  
  32.     public void onCreate(Bundle savedInstanceState) {
  33.  
  34.         super.onCreate(savedInstanceState);
  35.  
  36.        
  37.  
  38.         //Background bitmap
  39.  
  40.         Bitmap background_bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.fond);
  41.  
  42.         //Canva
  43.  
  44.         Canvas canva_1 = new Canvas(this);
  45.  
  46.  
  47.  
  48.         //Secondary bitmap
  49.  
  50.         Bitmap stamp = BitmapFactory.decodeResource(getResources(),R.drawable.icon);
  51.  
  52.  
  53.  
  54.         Paint brush = new Paint();
  55.  
  56.        
  57.  
  58.         canva_1.setBitmap(background_bitmap);
  59.  
  60.         canva_1.drawPaint(brush);
  61.  
  62.        
  63.  
  64.        
  65.  
  66.         canva_1.drawBitmap(stamp, 0, 0, brush);
  67.  
  68.        
  69.  
  70.         /Canva display
  71.  
  72.         setContentView(canva_1.save());
  73.  
  74.        
  75.  
  76.     }
  77.  
  78. }
  79.  
  80.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Thanks for uour attention! :mrgreen:
matt46
Freshman
Freshman
 
Posts: 6
Joined: Sat Nov 29, 2008 8:11 pm

Top

Postby MrSnowflake » Sat Nov 29, 2008 10:21 pm

Check this tutorial I wrote.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Thanks!

Postby matt46 » Sat Nov 29, 2008 11:13 pm

Thanks!
i'm gonna take a look at it! :)
matt46
Freshman
Freshman
 
Posts: 6
Joined: Sat Nov 29, 2008 8:11 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 21 guests