- How to implement an Inverse Filter?

by Gav » Wed, 17 Dec 2008 07:51:37 GMT

Sponsored Links

I am looking to make custom filters which manipulate the pixels of a
Bitmap. Before I can start I need to read up more on the Configs and
how they are encoded in the bitmap. I like to use examples so here's
my Inverse function;

        public Bitmap invert(final Bitmap d) {
                int index, r, g, b;
                int picw = d.getWidth();
                int pich = d.getHeight();

                int[] pix = new int[picw * pich];

                for (int y = 0; y < pich; y++){
                        for (int x = 0; x < picw; x++) {

                                index = y * picw + x;
                                r = 255 - ((pix[index] >> 16) & 0xff);
                                g = 255 - ((pix[index] >> 8) & 0xff);
                                b = 255 - (pix[index] & 0xff);

                                pix[index] = 0xff000000 | (r << 16) | (g << 8) 
| b;

                return Bitmap.createBitmap(pix, picw, pich, d.getConfig());

The bitmap returned is a white out which leads me to believe that my
assumption about the encoding of the RGB values is wrong. Upon further
investigation I found that the image could be any of the following


Which I would like to learn more about, can anyone point me in the
direction of an explanation of how these encodings work? I was wary of
material I found as it might not be the same standard Google uses.

If you can recommend a better way of inverting a Bitmap the
information would also be of substantial benefit for me.

Many thanks, any help or comments would be greatly appreciated!


Other Threads

1. How do I initiate/terminate xml-defined SurfaceView upon a button push?


I've patterned my initial code from another tutorial to create classes
to handle drawing to a SurfaceView.  This tutorial (and others I've
found) associate an xml-defined SurfaceView to a class which intiates
upon creation.

My goal is to initiate animation in an xml-defined surface view upon
pushing a button in my layout and terminating it when I push it
again.  Furthermore, the animation must run inside the region I've
specified in my xml (rather than the entire display) confined to that
region and not disturb the other widgets on the layout.

For simplicity, I'm currently only drawing a circle in the surfaceview
until I figure out how to get my layout working.

So, when I click the Go button (BattleActivity::onClick), my surface
view is created and drawn, but it fills the entire display covering
the other controls in my layout including the button.  I want the
animation to take place only in the surface view defined as part of my
layout (id=battleView).

Here's a sub-layout section of my XML code (tabBattle.xml).



                        android:text=" Go "


Here's my main activity class.  This is created when I navigate to the
tab view where its layout (tabBattle) resides.  The onClick is called
when I push the Go button.  My intention in onClick is to get the
surface view, create a new BattleView instance, and and pass the
surface view context to the BattleView constructor.   Based on my
tests, this clearly is not correct but I have no idea how else to
accomplish my goal.

public class BattleActivity extends Activity implements
    public void onCreate(Bundle savedInstanceState)

        public void onClick(View v)
                SurfaceView battleSurface =
                setContentView(new BattleView( battleSurface.getContext() ));

SurfaceView subclass:

public class BattleView extends SurfaceView implements
        private int circleRadius;
        private Paint circlePaint;
        UpdateThreadBattle updateThread;

        private int width;
        private int height;
        private int xPos;
        private int yPos;
        private int xVel;
        private int yVel;

        public BattleView(Context context)

            circleRadius = 10;
            circlePaint = new Paint();

        protected void onDraw(Canvas canvas) {
                canvas.drawCircle(xPos, yPos, circleRadius, circlePaint);

        public void surfaceCreated(SurfaceHolder holder)
                Rect surfaceFrame = holder.getSurfaceFrame();
                width = surfaceFrame.width();
                height = surfaceFrame.height();

                // do stuff herre

                updateThread = new UpdateThreadBattle(this);

        public void surfaceDestroyed(SurfaceHolder arg0)
                boolean retry = true;


                while (retry) {
                        try {
                                retry = false;
                        } catch (InterruptedException e) {



Any help is greatly appreciated!



2. MediaPlayer to play Multicast (igmp) medias?


I've been searching for a while for an example of the MediaPlayer, to
play multicast medias, such as live broadcast signals (e.g.
igmp://, by setting up my own multicast stream in

Is it possible through the MediaPlayer, or should I do a
MulticastSocket on my own, join the IP address and pass the file
descriptor to the MediaPlayer?.

Does anyone have examples of that or any experience?



3. Testing in app billing, all purchases end up cancelled

4. Flickr api connection with android

5. HelloAndroid] Unknown error: Unable to build: the file dx.jar was not loaded from the SDK folder!

6. android.R.styleable.Theme

7. bouncycastle CMS API works on Android 2.3 but failed on 2.2