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. Security model for location privacy

Hello all!

I am curious if the Android platform has a security model for
protecting the privacy of the user's location.  If there is, it is not
yet adequate.  In my opinion one of the biggest security concerns with
Android regards protecting the privacy of the user's location.  Is
anyone with me on this?

An Android user should be able to easily monitor and control which
applications have access to its current location information, and to
know exactly how that information is being used.  If there is an
active GPS uplink running through one of my apps, I really want to
know about it!

Currently an Android user can only chose to turn off GPS or disable
location services all together (and has to navigate through a few
settings menus in order to do so), and when GPS is turned on they can
only see when it is being used, but there is no way to see _what_ is
accessing it!

A reasonable security model would allow the user to grant or deny
access to positional information to specific apps.  Not only would
this help protect the user's privacy, but it would also help manage
battery resources!  For example, Android should expect the user to
allow the camera to geo-tag photos, turning on the GPS temporarily to
grab the position when needed, but there's no way we should expect a
paranoid or power-conscious user to turn on and off his GPS before
tagging a photo.  Additionally, the user should know if the app
tagging the photo also tries to post its location to a web server.
Relying on the one-time notification of which privileges are going to
be granted to the the app at application install just simply isn't
enough.

Another example:  I have an awesome app (Ecorio) that tracks my trips
and helps me to be mindful of my carbon footprint based on my mode of
transportation.  I would normally be thrilled about using this app,
but it is not clear what it is doing with my daily travel logs.  It
might be keeping them stored privately on my phone, or it might be
uploading them to Ecorio's server.  Android should let the user know
what is going on, and when, and should allow the user to deny specific
privileges to individual apps.

This is a very big security concern!  I've already been unpleasantly
surprised when I realized that my first test post - an embarrassing
photo tagged with my exact location - was publicly visible on a map on
the welcome page at wherester.com along with other recent posts.  The
Android platform should never allow an app to be so careless with my
privacy.

I'm still insanely e{*filter*}d about the future of Android and open mobile
app development, largely because I am confident that concerns like
these will be solved through the process of open collaboration.  But
before people will confidently adopt our location-based apps we need
to be to reassure them that the app isn't doing anything unexpected or
not allowed with its positional information.

Does anyone else share my concerns?  Is anyone already doing something
to address them?

Sam Hiatt

2. How to best build Android SDK samples in Eclipse?

Hello,

just use the new project wizard, and select "create project from
existing source".
You can then point the wizard to the ApiDemos folder.

Xav




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

3. How to see logs on PC.from connected G1 device

4. Taking the tutorial and have trouble with one of the steps

5. Android screen resolution limit

6. Android Crash Files

7. ImageView crash