Android : Want To Create Bitmap From BitmapDrawable?
May 26, 2009How can i convert a BitmapDrawable into a Bitmap (hopefully it keeps the Alphachannel from the BitmapDrawable)..
View 11 RepliesHow can i convert a BitmapDrawable into a Bitmap (hopefully it keeps the Alphachannel from the BitmapDrawable)..
View 11 RepliesI am 1) taking a picture and 2) then draw another Bitmap on top of it 3) then I store it
I am doing it as follows and it works on the emulator.
On the device I get a OutOfMemoryError: bitmap size exceeds VM budget android.graphics.Bitmap.nativeCopy(Native Method) android.graphics.Bitmap.copy(Bitmap.java:199) in the line copy the Bitmap to get a mutable Bitmap.
CODE:...........
What I am asking:
a) Is there a better way to do what I am doing? 1) take a picture 2) draw another Bitmap on top of it 3) then I store it
b) What is the best way to create a mutable Bitmap from the picture I just took with the camera?
In my app, resolution is not an issue. If it works better for small photos that would be fine.
How do I create a Bitmap from a byte[]?
View 2 Replies View RelatedI have an image in .png format in "drawable" folder and need to create Bitmap from it, so can use in public void drawBitmap (Bitmap<http://developer.android.com/reference/android/graphics/Bitmap.html>bitmap, float left, float top, Paint <http://developer.android.com/reference/android/graphics/Paint.html>paint)
View 2 Replies View RelatedI have a bitmap "picPrev" which I got from my online server. I want to turn it into a file so I can send it. I was exploring this method. code...
View 2 Replies View RelatedIs it possible to create a byte array from bitmap?How can I do so?
View 3 Replies View RelatedI am trying to build an Android application which can take several photos taken by the camera, and merge them into one giant image. For example, I might take three photos and arrange them in a vertical stack for output as a single image. Ideally, I'd like to be able to keep the images at the original size. Unfortunately, using Bitmap.createBitmap() causes an OutOfMemoryException before even approaching the size of one photo of camera dimensions. Is this possible? Or do I just need to resort to scaling the photos before trying to merge them into a single Bitmap?
View 1 Replies View RelatedI'm trying to create a MapView in a service (live wallpaper), but have it hidden so that I can render it to a Bitmap, and then map it to a texture to render in opengl. I have a Canvas and a Bitmap, and I intended to call myMap.draw(myCanvas) in order to get it into the correct bitmap so that I could then bind it as a texture.
When I Initialize I do the following:
myMap = new MapView(ctx, APPSTATICS.MAP_API_KEY);
I get an error:
java.lang.RuntimeException: stub at com.google.android.maps.MapView.<init> (Unknown Source)
Why I can't create a new mapview which I can use to draw to a offscreen bitmap?
I am using MediaStore.Images.Thumbnails.getThumbnail to create bitmap of thumbnail in htc hero , it takes lots of time to execute this. I other device it works faster. Please suggest any alternative to this method to create bitmap thumbnail so speed improves.
View 3 Replies View RelatedI have a problem - I am writing an application that displays up to 12 images on screen, and moves them around, plus reads touch events. I am using a sample code I found, and it works great. Now I need adding 3D - meaning emulating the objects moving in the Z axis, too (in/out of screen). To do this, I need to resize the images as they move. To test this, I changed the following line in my onDraw (Panel) code: canvas.drawBitmap(bitmap, coords.getX(), coords.getY(), null); to: Bitmap bmpScaled = Bitmap.createScaledBitmap(bitmap, 112, 112, false); canvas.drawBitmap(bmpScaled, coords.getX(), coords.getY(), null); Which works, BUT - movement on screen, plus response to touch events becomes real Jiggly. Checking the log I see that every call to createScaledBitmap causes garbage collection of around 90mS, which causes the total app to respond jiggly. Tried preparing 20 sized bitmaps beforehand, but since that moves the calls to those createScaledBitmap to the beginning of the app - it takes forever to load. Can you think of any workaround or other way to achieve the scaling effect?
View 3 Replies View RelatedI am trying to move my code from Java to C, and I have encountered a problem while trying to find a function in C that can take an array of ints and create a bitmap from it for OpenGL. In Java, I used
bitmap = Bitmap.createBitmap( {int array name} , w, h, Config.RGB_565);
Is there a similar function that I can use in C, or a workaround that I could use?
Also, if it matters, I am programming for Android.
I am banging my head against the wall trying to create a Bitmap from a Path object (android.graphics.Path). Is there any way to do this? I've browsed through most of the classes now but can't seem to find any way to do it.
Actually, what I have is a Path that consists of many cubic Bezier curves. It is really expensive to draw with canvas.drawPath(). So I figured that I could perhaps "cache" the Bitmap of this Path by converting the Path to a Bitmap once and then just drawing the Bitmap every time instead of calling canvas.drawPath().
Is there any way to create a Bitmap from this Path?
Or is there a smarter way to draw tha Path multiple times without having to recalculate all of the Beziers? For example, if I created a ShapeDrawable from PathShape from the Path, and just draw the ShapeDrawable objects every time, would that be more efficient than drawing the Path every time?
How to load an image file (on SD card) into a Bitmap on Android?
View 1 Replies View RelatedI have a very large image and I only want to display a section the size of the display (no scaling), and the section should just be the center of the image. Because the image is very large I cannot read the entire image into memory and then crop it. This is what I have so far but it will give OutOfMemory for large images. Also I don't think inSampleSize applies because I want to crop the image, not lower the resolution.
Uri data = getIntent().getData();
Input Stream is = getContentResolver().openInputStream(data);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, null);
Any help would be great?
I have two questions actually:
Is it better to draw an image on a bitmap or create a bitmap as resource and then draw it over a bitmap? Performance wise... which one is better?
If I want to draw something transparent over a bitmap, how would I go about doing it?
If I want to overlay one transparent bitmap over another, how would I do it?
My goal is the draw a bitmap onto another bitmap but rotated 90 degress. whats the most efficient way to do that. My current method is as follows which is horribly bad because it creates a new bitmap every time.
CODE:.....................
I want to draw a shape(many circles particularly) into a Specific Bitmap. I have never used canvas / 2D graphs etc. As i see it i create a Drawable put the bitmap in it then "canvas-it" to the shapes i want etc.
View 1 Replies View RelatedHow to create an HTTP request object of POST type in android? Which class need to be extend or what method need to implement? How to establish connection to a server? Actually i want to connect to a microsoft exchange server, and then i have to send a request to it using HTTP.
View 8 Replies View RelatedI'm trying to figure out how to draw on a bitmap in android, and keep a copy of these changed bitmaps for an undo function.
Bitmap b = ...
Paint p = new Paint();
canvas.drawBitmap(b, new Matrix(), null);
canvas.drawCircle(0,0,20,20);
//does Bitmap b have the circle drawn on it next time?
Or how do I get the bitmap after its been drawn on with the canvas(I want to preserve a stack of bitmaps with the changes applied by canvas drawing)? Maybe I'm going about this entirely wrong.
I am trying to grayscale bitmap as follows, But it is crashing as soon as I run this method.
The problem is in last line. How can I assign "int" to "Color"? Or are there any better ways?
CODE:................
I want to get the bitmap that is drawn when a textview is displayed but without displaying the textview in the activity. something like this:
TextView t = new TextView(this);
t.forceToDrawItself();
Bitmap b=t.getViewBitmap();
how is this possible?
Does anybody knows how can I put a Bitmap on top of a button, but without taking the whole surface?
View 2 Replies View RelatedI want to resize a bitmap and write to a file. what's the best way to do that?
View 2 Replies View RelatedI have two different bitmap. Can I merge these two bitmap into one?
View 7 Replies View RelatedI have a Bitmap image and i want to forward the bitmap to another activity. I have two activities Activity A and Activity B. This is how I started the Activity B
startActivityForResult(new Intent(Activity A.this, Activity B.class), 120);
in activity B
private void forwardImage(Bitmap bit) {
Intent i = new Intent(MMS.this, Compose.class);
i.putExtra("MMS", bit);
setResult(RESULT_OK, i);
finish(); }
This is not forwarding to Activity A but if I put a String to the intent it'll forward. This is how I listen to result in Activity A
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
// super.onActivityResult(requestCode, resultCode, data);
switch (resultCode)
case RESULT_OK: Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("MMS");
mmsImage.setImageBitmap(bitmap);
default: break;
} }
How can I pass a bitmap.
I have a bitmap displayed on ImageView now i want to give a facility to write comment typed by the user on that bitmap.i tried using Canvas canvas = new Canvas(srcBitmap); canvas.drawText("Hello", 100,100,null);but this is giving me following error java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor later on i want to save this whole image a bitmap.
View 1 Replies View RelatedIs there an easy way to replace a colour in a bitmap?
View 2 Replies View RelatedI would like to convert a Bitmap to a grayscale array of bytes (one byte per pixel). At the same time I want to just crop at section from the middle. Having looked though the various api's it is not clear to me what the best way would be.
1) What is ALPHA_8? is that grayscale? I have a feeling that the grayscale effect should be done via some "saturation" on the paint object, right?
2) once I have the Bitmap in grayscale and the right size, what is the best way to get that to a byte[] of pixels (one byte per pixel)?
I have a picture taken using the phone's camera and in bitmap format. I want to send it over HTTP usinf Http post in ASCII.Any idea how to do it?
View 4 Replies View Relatedthis problem has been bothering me for days and I cannot figure out why on earth it is happening. I have a method that detects for a face, if a face is detected, the method will draw a rectangle on a canvas along the face.That part works fine.The problem is, when it displays to the image_view in my xml file, it will display on the far left middle of the image view, in a box, rather than in the center with the width as fill_parent.I thought of a possible workaround : to set the bitmap as a bitmapdrawable, but canvas only draws to bitmaps, so I can get the bitmapdrawable in the middle, but with no red box around it.I commented out my testing of bitmap drawable, and left it as what I have now...it only displays to my xml in the far left of the image_view.
View 1 Replies View Related