[Q] creating a bitmap - Android Software Development

how do I create a bitmap from a png image?

This turns a png into a bitmap:
Bitmap bmp = BitmapFactory.decodeResource(activity.getResources(), R.drawable.myPNGimage);
I think your other post asked about drawing images onto the screen. To do this, you need an object that you want to "draw onto".
So in this example, lets say you want to draw "bmp" onto "backgroundBmp". (Pretend "backgroundBmp" is a 400x400 pixel image)
Canvas canvas = new Canvas(backgroundBmp); // This creates a canvas to work with, thats the size of backgroundBmp (400x400)
Now I can draw a bitmap onto it, by doing:
canvas.drawBitmap(bmp, x, y, null); // This draws bmp at (x,y) coordinates on the canvas.

Take a look at the Lunar Lander and Jet Boy sample applications at developer.android.com.

Related

[Q] using getSurfaceFrame to get display width/height?

So I'm trying out making a live wallpaper and I'm using the sample code provided in the SDK for the cube live wallpaper
I wanted to use this code to get the height/width of the display
Code:
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
Rect frame = getSurfaceHolder().getSurfaceFrame();
float width = frame.width();
float height = frame.height();
// By default, we don't get touch events, so enable them.
setTouchEventsEnabled(true);
}
and if you're wondering about the context of the code, just look at this sample
Unfortunately, when I run this code, the width and height return as 0, though if I put this in onVisibilityChanged, the correct values are returned, why is this and where should I put it?
Also, when I do get the display width/height, it includes the real estate behind the notification bar as well. Is there a way I can get the width/height area of everything excluding the notification bar?

[Q] Problem cropping picture on Droid 2

In my app, I allow the user to capture a new image and then I launch an intent to crop the image. When the intent returns, the image has been cropped but the device's wallpaper has now also changed to the newly captured/cropped image!! How can I avoid this side-effect?
I noticed that the contacts app has a similar flow when you assign a picture to a contact and their newly captured images do not affect the wallpaper. What should I be doing differently? This is the intent I use to crop the image:
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(Uri.fromFile(cameraCaptureFile), "image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", cropX);
intent.putExtra("outputY", cropY);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraCropFile));
Thanks!

[Q] easiest way to draw a sprite

whats the easiest way to draw a sprite or paste a png image that has x, y coordinates?
Pull the png in as a Bitmap object, and then draw the bitmap onto a Canvas.

[Q] How do I set a color to be transparent ImageView

I have a ImageView with a bitmap on on top of a FrameLayout. To get this bitmap I converted a png w/ transparent background to bitmap. So all the transparency turned into black. How do i set that black to be transparant.
Thankyou
could you be more specific to help you. i can't get your question probably please bare with me. thanks
Only by not using a bitmap. Why did you convert the png (that supports transparency) to a bitmap (that doesn't support transparency) anyway?

Android theming language

Hey guys good days
I just want to ask maybe this is off topic but i just can apply the code provided by devs without understanding what the mean of it.
So i want to know where do you guys learn it ?
Example what is image view, frame layout, linear layout and so on.
If you learn it from book, can i know the title of it ?
TIA
Try
http://developer.android.com/reference/packages.html
http://developer.android.com/reference/android/widget/LinearLayout.html
and specially
http://forum.xda-developers.com/coding/education
ImageView = its imageview the one that containing image like a pictureFrame.
LinearLayout = its a linearLayout. For example you want to put imageView inside a LinearLayout
its like putting a pictureFrame in a wall.
LinearLayout Orientation = vertical - make the child vertically arrange.
for example you have three picture frames in a wall and you add androidrientation="vertical" the picture frame will be aligned verticaly same with androidrientation="horizontal" this will arrange the child horizontally.
FrameLayout = like LinearLayout but this layout makes you put Layout in top of other Layout.
:good::good::good::fingers-crossed::fingers-crossed::fingers-crossed::good::good::good:​

Categories

Resources