How to draw a piece of Bitmap

by Nick » Tue, 10 Mar 2009 01:09:37 GMT


Sponsored Links
 Hello!
I'm creating a simple game for Android and faced with a problem: Idea
is to have a huge "map" image file and re-draw only small part of it
(320*480) depending on user actions.

I didn't find a better solution than using "public static Bitmap
createBitmap (Bitmap source, int x, int y, int width, int height)"
method and decided to try it (expected huge performance degradation),
but actually it's appeared that this method changes source bitmap and
when i call it second time source size is significantly reduced. For
instance this code:

int bitHeight = mBackgroundImage.getHeight();
int bitWidth = mBackgroundImage.getWidth();
Bitmap curMap = Bitmap.createBitmap(mBackgroundImage,
                0, mY, 320, 480);
canvas.drawBitmap(curMap, 0, 0, null);

gives 320*960 (initial source image size) size for the first time and
320*455 for the second call

I hope this is not a best solution and look forward to hearing a new
direction or at least clarification on createBitmap method.

p.s i'm not a native english speaker and i apologise for possible
mistakes.

--~--~---------~--~----~------------~-------~--~----~



How to draw a piece of Bitmap

by Ikon » Mon, 27 Apr 2009 06:33:40 GMT


 Nick, Did you figure this one out? I want to do the same.



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


How to draw a piece of Bitmap

by Nick » Mon, 27 Apr 2009 21:06:10 GMT


 Yes, I managed with this "problem".
I use specific drawBitmap method of Canvas class - public void
drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint)
Example:
Rect rect = new Rect(0, mCanvasHeight - mY, mCanvasHeight,
mBackgroundHeight - mY);
Rect rect2 = new Rect(0, 0, mCanvasWidth, mCanvasHeight);
canvas.drawBitmap(mBackgroundImage, rect, rect2, null);
//increment mY each time you need and your picture would be "moving"
forward:)

As for unexpected resizing - usual copy/paste :) - I used LunarLander
SDK example for my experiments and didn't notice this code:
  // don't forget to resize the background image
                mBackgroundImage = mBackgroundImage.createScaledBitmap
(
                        mBackgroundImage, width, height, true);

in setSurfaceSize method. So I actually worked with "updated" copy of
my background image in my code.

That's it.





--~--~---------~--~----~------------~-------~--~----~



How to draw a piece of Bitmap

by Streets Of Boston » Mon, 27 Apr 2009 22:22:17 GMT


 My app zooms in and out of pics and lets the user moved the (zoomed)
in pic around.
The key methods for mapping a sub-picture (the one the size of the
screen) is done by using the calls Matrix.setRectToRect and
Bitmap.createBitmap(Bitmap source, int x, int y, int width, int
height, Matrix m, boolean filter), with x=y=0 (letting the Matrix m do
all the translations), and 'width' and 'height' set to the size of the
full-sized image (letting the Matrix m do all the scaling).




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. OMAP35x EVM .config for 2.6.27 kernel

Can anyone share or provide a link to  Android ready .config for the
OMAP35X EVM?  I would like to get Android (Cupcake) running on this
board.

Does anyone know of an available porting guide that includes support
for the EVM?

Regards,
Nestor
--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Query about Content Provider queries...

> In terms of existing providers,

Generally speaking, the former is impossible, since you won't have access
to the database (e.g., security), if there even is a database, which is
far from a given.


Content providers do not need to use SQLite as a data store. They could
use flat files, Web services, third-party object databases, SD card
directory trees, random number generators, etc.

There is a subset of content providers that will use SQLite as a data
store. What Ms. Hackborn is suggesting is that those content providers
could offer distinct, etc. via their own exported Uri pattern. What you
seem to be proposing is to force developers to implement all the SQL
options for data stores that aren't SQL, which may not be a popular
answer.


Again, content providers do not need to use SQLite as a data store.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~---------~--~----~------------~-------~--~----~

3. Two different views with CursorAdapter

4. Enabling route table with Custom Wifi driver

5. Saving/Loading dynamic Bitmaps

6. Does Android need a more compelling/smoother user interface? (consumer view)

7. How do you get in touch with Google Android Staff?