How to modify the image file

Put your problem here if it does not fit any of the other categories.

How to modify the image file

Postby NeoLiu » Sun Jan 13, 2008 8:28 am

Hi guys
In my code
i want touch point on the image.

Bitmap = BitmapFactory.decode(path);

but the bitmap is immutable.

how to set the bitmap to mutable.
NeoLiu
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Jan 07, 2008 3:27 am

Top

Postby plusminus » Sun Jan 13, 2008 11:16 am

Hello NeoLiu,

the only static "constructor" for Bitmap returning a mutable one is:
(Class: Bitmap) public static Bitmap createBitmap(int width, int height, boolean hasAlpha)
Returns: a mutable bitmap with the specified width and height.


So you could work with getPixels/setPixels or like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         Bitmap bitmapResult = bm.createBitmap(widthOfOld, heightOfOld, hasAlpha);
  2.         Canvas c = new Canvas();
  3.         c.setDevice(bitmapResult); // drawXY will result on that Bitmap
  4.         c.drawBitmap(bitmapOld, left, top, paint);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Re: How to modify the image file

Postby NeoLiu » Mon Jan 14, 2008 3:37 am

Hi plusminus

i can modify the image content when i used this method

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         Resources r = this.getContext().getResources();
  2.  
  3.         loadTile(r.getDrawable(R.drawable.a));
  4.  
  5.  
  6.  
  7.     public void loadTile(Drawable tile) {
  8.  
  9.         Bitmap bitmap = Bitmap.createBitmap(maxEditWidth, maxEditHeight, true);
  10.  
  11.         Canvas canvas = new Canvas(bitmap);
  12.  
  13.         tile.setBounds(0, 0, maxEditWidth, maxEditHeight);
  14.  
  15.         tile.draw(canvas);
  16.  
  17.         mBitmap = bitmap;
  18.  
  19.         mCanvas = canvas;
  20.  
  21.     }
  22.  
  23.  
  24.  
  25.  
  26.  
  27.     protected void onDraw(Canvas canvas) {
  28.  
  29.         if (mBitmap != null) {
  30.  
  31.             canvas.drawBitmap(mBitmap, 0, 0, null);
  32.  
  33.             //canvas.drawBitmap(BitmapA, 0, 0, null);
  34.  
  35.         }
  36.  
  37.     }
  38.  
  39.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


but i have a new problem, how to get the drawable from Bitmap
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. BitmapA = BitmapFactory.decode(path);
  2.  
  3.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

Drawable ?
NeoLiu
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Jan 07, 2008 3:27 am

Postby plusminus » Mon Jan 14, 2008 8:32 am

Hello NeoLiu,

by using the BitmapDrawable-Subclass which extends Drawable, like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         Bitmap myBitmap = BitmapFactory.decode(path);
  2.         Drawable bd = new BitmapDrawable(myBitmap);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Let us know if it helped you.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Re: How to modify the image file

Postby NeoLiu » Tue Jan 15, 2008 3:06 am

Thanks, it works :D
NeoLiu
Junior Developer
Junior Developer
 
Posts: 17
Joined: Mon Jan 07, 2008 3:27 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 19 guests