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. RampUp the binding b/w Activity & Service

Hi all,

I am looking for a mechanism to ramp up the binding between
Activity and a Service.

*I have a:
*I have a java library wrapping up the service, Which does the binding.
*Looking for:
*A way to have a worker thread (Looper, etc ) to process the bindService
call and give a callback to onServiceConnected();

As fast as the instantiation of the class would take,

Is this approach worth giving a try.  If so, Can any one guide me to make
 this approach work.

Any suggestions would be helpful..

-- 
Shine bright,
(: Naveen Krishna Ch :)

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

2. Start Activity With Long Press of Home Key

> Everything I read said that essentially any part of the phone could be

First, most likely what you read refers to the fact that Android is open
source, and so you can build your own firmware and deploy it on your own
devices with whatever changes/replacements you want.

Even beyond that, SDK applications have a fair bit of control to provide
alternatives for built-in capabilities, though there it is providing
*alternatives*, not usually outright replacements, and also only where
there are appropriate hooks.

What you're trying to do is say that, from an end-user application, you
want to replace the right-mouse menu when you click on the desktop
background of Windows or Linux. Or you're trying to replace the
font-picker drop-down list in Microsoft Word or OpenOffice.org.
Fine-grained features like that are not necessarily designed to be
replaced in isolation without replacing more of the product. You see this
with all sorts of applications and platforms.


If you are willing to modify the firmware and distribute those
modifications, you can change whatever you want. By my reading of the
Android source code, you cannot change what happens on a long-press from
an SDK application. Since you are on [android-beginners], my assumption is
that you are trying to build an SDK application.


You are certainly welcome to your opinion, just as I am welcome to my
opinion that your expectations are unrealistic, even for the most open
source of projects.


http://b.android.com

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html



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

3. How can I add a background image for ListView

4. can we record only aac stream?

5. Orientation Sensor return false values. And getRotationMatrix() also doesn't work. Is my ADP1 broke?

6. MediaScannerConnectionClient which content provider?

7. About to receive the mms