Android :: Compare Bitmaps In Canvas
Aug 18, 2010I am using the above code for displaying bitmap.and i also move that bitmap.Now my qusetion is how i am compare bitmap with another bitmap. Please give me some suggestions.
View 2 RepliesI am using the above code for displaying bitmap.and i also move that bitmap.Now my qusetion is how i am compare bitmap with another bitmap. Please give me some suggestions.
View 2 RepliesI have following example code:
Character c = CharacterFactory.getCharacter(CharacterEnum.SpecialCharacter); //factory has applicationContext reference to get bitmaps from R. ... Paint bitmapPaint = new Paint(); ... View::onDraw(Canvas canvas) ... canvas.drawBitmap(c.bitmap(), 0, 0, bitmapPaint);
For some reason (must be something simple) I do not see the bitmaps at the 0,0 of the canvas. Inspecting the bitmap and etc does not show anything obvious (nulls), I must have missed something. Is there something I should be paying particular attention to while drawing bitmaps?
I have two bitmap overlapped .The top bitmap is transparent and when user touch to screen i copy pixels from another bitmap to top bitmap.My goal is to give to users the feeling of erasing image with touching to see another image.However it is not working properly especially when user drags his finger too fast on the screen.I made a few tests and i beleive drawing bitmaps to the canvas every time cause the lag but i don't know how to fix it.
View 1 Replies View RelatedI have a Bitmap object and want to render it to a Canvas object with varying levels of translucency (i.e. make the whole bitmap partially see through). For example, I have sprites in a game (that are drawn over the top of a bitmap background) that I want to fade out from being opaque to being invisible. Can I do this without having to resort to OpenGL?
View 2 Replies View RelatedI currently have a game written using the Android canvas. It is completely 2D, and I draw bitmaps as sprites on the canvas, and it technically works, but I have a few features that I need to add that will require drawing many more bitmaps on the screen, and there will be a lot more movement.
The app needs more power.
What is the best way to go from this method of drawing Bitmaps on a canvas to using OpenGL so I can draw them faster?
My loadMap() method generate a canvas.throwIfRecycled exception when i try to load a new map.
When i start the game, the initial map loads and work fine though,
its only when i try to load a new map that i get the exception ..
How can i "reset" canvas and the bitmap i use to draw into, so i can startover fresh with them ?
here's what i use to create and draw my maps:
CODE:.........
So basicaly once i created and used picDest and canvas, i cannot figure how to reset it all for when i want to load a new map..
I am writing a clock widget that uses customised bitmaps (so the widget loads the bitmap from the sdcard) Just have a couple of questions regarding how updates work:
1. if i want to display seconds on the clock widget will the widget load the bitmaps off the disk every second or can they be cached somehow so it doesn't reload off the disk each time. or If it does reload a bitmap each second, would this use a lot of power?
2. If i load the customised number bitmaps into a static array and then pass them as bitmaps to the widget would this use less power than just loading off the SD card?
I want to load bitmaps into ImageViews in Android, but I don't want to use the R.drawable syntax because I have a lot of images with a standard naming convention so it's much easier to get the image with some logic. For example, all my images are named:
img1.png
img2.png
img3.png
So if a user selects a value, let's say x, I show "img" + x + ".png" in the ImageView. Looks like Bitmap.decodeFile is what I need, but I need to know the syntax of how to get to my drawables folder since that's where the images are. Or if there's perhaps a better way.
I realize I could do this with a switch statement instead of concatenating the image name but that would be a lot of lines since I have so many images.
I am struggling to get Bitmaps blurred using Android.
I have seen a lot of information about using a simple kernel like
0 0 0 5 0 0 0
0 5 18 32 18 5 0
0 18 64 100 64 18 0
5 32 100 100 100 32 5
0 18 64 100 64 18 0
0 5 18 32 18 5 0
0 0 0 5 0 0 0
My problem is that I am really not sure how to multiply this with my Bitmap in an efficient way. Should I go through every pixel and image.getPixel(x, y)
while storing those values to a new array (so I don't have to get those values over and over again) and then go through the array and for each value add up the surrounding values multiplied by the corresponding field in the kernel divided by 1068 (in the case of the above kernel (= all entries summed up))?
Is there any better way to do this? Is there a simple solution for the borders?
Or is there even something available in the Android SDK I missed?
I am working on an application that downloads images from a url. The problem is that only some images are being correctly downloaded and others are not. First off, here is the problem code:
public Bitmap downloadImage(String url) {
HttpClient client = new DefaultHttpClient();
HttpResponse response = null;
try {.......................................
So what I have is a method that takes the url as a string argument and then downloads the image, converts the HttpResponse stream to a bitmap by means of the BitmapFactory.decodeStream method, and returns it. The problem is that when I am on a slow network connection (almost always 3G rather than Wi-Fi) some images are converted to null--not all of them, only some of them. Using a Wi-Fi connection works perfectly; all the images are downloaded and converted properly. Does anyone know why this is happening? Or better, how can I fix this? How would I even go about testing to determine the problem?
How can one track memory consumption in Android? The Android "Heap" view in Eclipse and java.lang.Runtime methods seem failing for my purpose. I tried to figure out how much memory my app consumes in order to make decisions for future directions. Most of the memory goes into Bitmap objects. Just to test memory consumption I created huge bitmaps in a Loop and logged the java.lang.Runtime memory values: created bitmap (610k free, 2371k total, 16384k max) created bitmap (615k free, 2371k total, 16384k max) created bitmap (615k free, 2371k total, 16384k max) created bitmap (615k free, 2371k total, 16384k max)
Nothing seems to hapen, but on the fifth Bitmap: java.lang.OutOfMemoryError: bitmap size exceeds VM budget at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:343) at de.greenrobot.colorball.GameView.init(GameView.java:86)
This seems confusing at first. Is java.lang.Runtime the right place to check application memory stats in Android at all? Are Bitmaps allocated outside the app's heap? How can I track it?
I'm running into OutOfMemoryErrors when allocating bitmaps. This is not something I can reproduce with emulators, and has been reported by a few beta testers with the HTC Incredible. I'm not sure I can solve this directly, and my best hope is to follow best practices for bitmaps and memory thereof. But looking for those best practices based on groups archives left me with more questions than answers. If anyone has a chapter about this in their book, I will buy the book. Here are the things I've mulled over so far:
1. I have a bitmap for a drawing buffer. It is about 3-4 megabytes on some devices. This is the biggest bitmap I have, and without it, I wouldn't be able to much of anything useful in my app. I am assuming that it would not be useful to use inPurgeable if this is a bitmap that is drawn into. Is this true?
2. Next biggest in the hierarchy are some bitmaps that are about 22K bytes and 256K unpacked. Since I believe about 25 of these might be used at one time, I have a cache with a size of 25. I am careful to use BitmapFactory.Options.InPurgeable, so I believe that could make them take only 22K each, but I don't see that as guaranteed. Maybe they are taking 256K each, which would put me in the danger zone. As they are cycled out of the cache, I call bitmap.recycle(). I think this a good practice. Is it?
3. Next are some resources with icon size 32x32 pixels. There are about 50 that could be used or reused. If I use code like this:
Drawable s = mCtx.getResources().getDrawable(R.drawable.symbol_icon);
Where s is a local variable to rendering. Suppose I call this 37 times. Am I to assume that Android will do something smart like create only one bitmap for this resource even if it is used 37 times? Or am I to assume that Android will do something stupid like create 37 bitmaps and keep references in an obscure location that will prevent garbage collection? Do I need to get more access to these bitmaps and do something smart myself?
4. Finally are some other icons used for menus and ImageButtons. Most are declared in layout files - so I don't touch the bitmaps directly.
I'd like to make my memory usage more efficient, but don't want to spend time on things that will amount to shuffling chairs on the Titanic. And how do I best measure this usage? Interestingly enough, I've tried using the Allocation Tracker and it says I haven't allocated a single bitmap. In light of the above, I don't think that's right.
Our app has some memory peaks, which let the heap grow to 13M. After the peak, there's 9M of free heap. Everything's fine until Bitmap objects come into play. Despite having 9M of free heap creating Bitmaps, which have only some 100k, now fail with a OutOfMemoryException!
My theory: Allocation fails if (Java) heap *size* plus external allocations (e.g. Bitmaps) exceed 16M, no matter that there is lots of free memory in the heap. The VM could shrink the heap, but actually does not. Would be quite a flaw in the VM.
Does anyone share this theory?
On the downside of this theory: I do not see anything appropriate (killing the process is probably not) an app developer could do to prevent those OutOfMemoryExceptions given that those memory peaks are legitimate and unavoidable.
I have an application that receives information from a database, and is used to visualize 2D bitmaps onto a GLSurfaceView. The information received will determine the x-position of the bitmap, and which bitmap image to use (there are 4 different bitmaps in my res folder to choose from).
Below are the three classes that are being used. The Activity sets the Shapes objects that need to be drawn by passing an ArrayList to the GLLayer class. This ArrayList is passed to the instance of ShapeStorage class via another setList method. This class is responsible for drawing when they are received.
The problem that I'm having is the following. Suppose I receive one object (let's say that it's a square at it's located at x=1). Some time goes by, and I receive another shape (this time, it's a triangle, and it's located at x=-1). However, when this new shape appears on the screen, the old bitmap's appearance changes to a triangle, and the new one becomes a square. In other words, the objects themselves are at the correct position that they are supposed to be at, but the bitmap being associated with them has changed. Does anyone know what the possible cause of this can be? I'm still a newbie to OpenGL-ES, and while this code looks very convoluted, it just involves setting a bunch of various properties for the View. code...
I definitely have a memory leak problem and i'm trying to figure out there. After 6-10 config changes i'm getting out of memory in regards to BitmapFactory. I'm kind of suspect that this is going on within adapter. I have a listview . ListItems are an thumbnail image ( ImageView ) and TextView for text.
Here is the getView code.
CODE:..................
And get ThumbnailBitmap() is basically BitmapFactory.decodeByteArray ..
Is it possible that i'm leaking drawables ? Heap is not increasing by the way .
I used this sort of code to make sure my bitmaps load:................
In 2.2, it's now failing sometimes and my catch block no longer catches anything. Why would that be? Is there a better way to avoid a java.lang.OutOfMemoryError?
I am creating a CustomView with bigger image based on tutorial on and developers forum. It is scolling fine.I need exact pixel coordinates of my image.I am getting that also.now I want to draw some images upon scrolling image.I am able to draw images using onDraw().But images are not getting scrolled.Any idea how to resolve this?
View 4 Replies View RelatedWhen I load an image frome the media gallery into a Bitmap, everything works fine, except that pictures that were shot with the camera while holding the phone vertically, are rotated so that I always get a horizontal picture even though it appears vertical in the gallery. how can I load it correctly?
View 3 Replies View RelatedI want to make a tile based game for android. At the moment I am drawing each tile as a separate bitmap. I have a big for loop that reads from a string and draws different tiles depending on what character it finds to draw the level. I have allowed the user to scroll the screen using scrolling gestures. However the game is too slow. It takes a long time to update the screen after the user scrolls. I presume this is because it has to draw each tile's bitmap individually. What would be a faster way to draw the level? I was thinking I could merge all the tiles into one bitmap. But I don't know how to do this.
Anyway here is my code so you can see the problem:
package org.example.tutorial2d;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
import org.example.tutorial2d.Panel;
public class Tutorial2D extends Activity implements OnGestureListener {
GestureDetector gestureScanner; Panel main;
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gestureScanner = new GestureDetector(this);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
main = new Panel(this); setContentView(main); }
@Override public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me); }
@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
main.handleScroll(distanceX,distanceY); return true; }
@Override public boolean onDown(MotionEvent e) { return true;
} @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return true;
} @Override public void onLongPress(MotionEvent e){
} @Override public void onShowPress(MotionEvent e) {
} @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }
And the class that does all the work:
package org.example.tutorial2d;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import org.example.tutorial2d.Point;
public class Panel extends View {
private int scrollX = 0; private int scrollY = 0;
public Panel(Context context) { super(context);
} @Override public void onDraw(Canvas canvas) {
/*Bitmap scratch; //Drawable scratch;
//scratch = getContext().getResources().getDrawable(
// R.drawable.icon); canvas.drawColor(Color.BLACK);
//scratch.draw(canvas); int origin = 0;
scratch = BitmapFactory.decodeResource(getResources(), R.drawable.horizontal5);
canvas.drawBitmap(scratch, origin, origin, null);
int width = scratch.getWidth(); int height = scratch.getHeight();
scratch = BitmapFactory.decodeResource(getResources(), R.drawable.room4entrynesw3x3);
canvas.drawBitmap(scratch, origin + width, origin - 32, null);
[Code]
We are also having occasional problems with OutOfMemory errors in createBitmap. It tends to happen after a few orientation changes when we are allocating the backbuffers. I have made it so that it calls recycle() on the old bitmaps (if any exist) and does a System.gc() before allocating the new backbuffers. What we are doing is allocating a backbuffer that is twice the width and height of the screen so that we can quickly zoom in and out.
With a 854x480 screen this would presumably be 6.25MB in size. The problem as I see it is the 16 or 24MB maximum heap size per process. This is unreasonably small, especially on devices that have 512MB of RAM. Ideally the max heap size should be something like 64MB, or perhaps allow apps to request a larger heap size from the user.
Can anyone tell me how to combine or concatenate two bitmap images into one in android?
View 2 Replies View RelatedI have a scrollable map app which for now has a huge bitmap. It loads fine on startup, but when it looses foreground status and the user brings it backs again im getting an out of memory error. In onPause it trashes the bitmap using recycle, and marks it as null. The onResume checks to see if map==null and will load the bitmap back again, which is crashing the program despite me recycling the bitmap...Here are some bits of code. All of the other references to Bitmap map first check if it is null before loading/drawing..............
View 1 Replies View RelatedSo, I'm currently a BlackBerry (9700, for the record) user, seriously considering switching to an android device. I'm sure everyone here can account for the various ways an android phone is superior to a BlackBerry, and I'm pretty familiar with them. What's been holding me back though, are the minor productivity tweaks a BlackBerry provides that seemingly don't have a match on android devices. Am I wrong on these? Have others made the jump and found no difference? Specifically: Dedicated hotkeys of sorts -- I'm a pretty heavy business user, so I make ridiculously extensive use of my calendar/scheduler. No matter what I'm doing at the moment, I'm able to jump to my calendar with a single button press and see my entire week's worth of appointments. If I need to add something, I can schedule an appointment in under 5 seconds all the way through. To be honest, that's probably the only hotkey I use, but the ability to do this in an instant no matter what's in my way is rather important for me -- are there any equivalents on android phones? Through my research I've noticed a lack of hardware hotkeys. Is there any software solution that could at least compare?.....
View 16 Replies View RelatedI am currently working on an app and I want to lay a Bitmap over the Google Maps bitmap with the click of a button. I am assuming this is possible, and maybe a lot easier than I'm making it.
class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
[Code] ......
In my app on cupcake platform ,in the EGLDisplaySurface.cpp ,my plan is adding a method to compare the data is different or not between front buffer and back buffer.but I can't understand the framebuffer is.I'm poor in C++.
View 3 Replies View RelatedI would like to compare two song files (one may be subset of other file) and see, if they are match each other. Is there any predefined method available in Android? How to proceed on this?
View 5 Replies View RelatedI am thinking of developing a small application and I am trying to decide between various Mobile applications platforms - Android, iPhone and RIMM. I was wondering if any of you have any thoughts on any of these mobile platforms, there advantages/disadvantages etc. Also - how would you compare between the various app stores these mobile platforms have.
View 2 Replies View RelatedI am starting to regret my purchase of the Samsung Moment, I dont know if its with the Lacking OS of 1.5 as I see 2.0 on the website the interface is different with the phonebook, the way the screen looks. I still have yet to figure out how really this phone is the "same" or compares to the IPhone ... in simple ways of application use, I still see my friends on their I Phones talking to millions of people with in a 5 mile range to a 100 mile range on all these social applications.With also that in talk of Applications why is it when i try to get a NEW! or POPULAR! application I have the wrong OS I am starting to think I should of held out for the Nexus unlocked cause I think that is the only one you can get that does everything. I was really hoping for a socialized phone not a traveling phone. I will say it is handy ,when you go into the store to compare prices or when you go on a long trip finding restaurants,gas stations and such but the I phone helps everyone connect and thats what I really would like to see a SOCIAL app for ALL android USERS together!
View 12 Replies View RelatedI'll get straight to the point. Please note that I haven't code anything in this project just yet. This is only an idea. In human language, my goal is to: 1. Take a picture of a blank white A4 paper. 2. Verify (by code) that the picture is "White". (this's why I include 'simple' in the topic) I mean, the program should be able to tell if the user just took the picture of "white" paper and not any other colors. For the code... I can guess that the actual process should be: 1. Use Camera API to take a picture. // this step should be easy 2. Convert it to Bitmap. // this step should also be easy 3. Verify that it is "White". //*** now I need some help here. How can I do step 3? I look up the docs and found this is the Bitmap class: getPixels (int[] pixels, int offset, int stride, int x, int y, int width, int height) I can use this and compare the data pixel-by-pixel but it seems expensive. Could anyone recommend me a more proper way(if there is) to do this please?
View 4 Replies View RelatedI'm trying to compare two datetimes but I can't get it to work. Code...
View 1 Replies View Related