Creating a new image from the old one...

All your problems with Audio, Video and Images.

Creating a new image from the old one...

Postby strider2023 » Fri Mar 05, 2010 11:15 am

Hello World,

Well i writing a program to create a new image from an old image which will only have the old image's R channel...i am here by attaching the code of what i have done so far...but have no clue how to create the new image with the new values.. Pls help...
Code: Select all
package test.app;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.View;
import android.view.Window;

public class Base extends Activity {
   
   private ByteBuffer src = null;
   private int data = 0;
   private int picw = 0,pich = 0, newWidth = 0, newHeight = 0;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(new Panel(this));
    }

    class Panel extends View {
        public Panel(Context context) {
            super(context);
        }

        @Override
        public void onDraw(Canvas canvas) {
            Bitmap testimage = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
            //Bitmap testimage1 = null;
            //Bitmap testimage1 = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
            data = ((testimage.getWidth() * testimage.getHeight()));
            System.out.println("Lines of RGB values to be printed: " + data);
           
            /*
             * Getting the values
             */
           
            picw = testimage.getWidth();
            pich = testimage.getHeight();
            newWidth = 200;
            newHeight = 200;
           
            //calculate the scale
            float scaleWidth = ((float) newWidth) / picw;
            float scaleHeight = ((float) newHeight) / pich;
           
            // create the matrix for manupulation
            Matrix matrix = new Matrix();
            //resize the bitmap
            //matrix.postScale(scaleWidth, scaleHeight);
           
            int[] pix = new int[picw * pich];
            testimage.getPixels(pix, 0, picw, 0, 0, picw, pich);
            for (int y=0; y<pich; y++) {
               for (int x=0; x<picw; x++) {
                  int index = y * picw + x;
                  int R = (pix[index] >> 16) & 0xff; // bitwise shifting
                  int G = (pix[index] >> 8) & 0x00;  // bitwise shifting
                  int B = pix[index] & 0x00;         // bitwise shifting
                  //R, G, B print values.
                  System.out.println("RGB: " + R + ", " + G + ", " + B);
                  //to restore the values after rgb modification
                  pix[index] = 0xff000000 | (R << 16) | (G << 8) | B;
               }
            }
            //testimage1.setPixels(pix, 0, picw, 0, 0, picw, pich);   
            Bitmap testimage1 = Bitmap.createBitmap(testimage, 0, 0, picw, pich, matrix, true);
           
            //src = ByteBuffer.allocate(data * 4);
            //src.order(ByteOrder.nativeOrder());
            System.out.println("allocate");
         //testimage.copyPixelsToBuffer(src);
         //System.out.println(src);
            canvas.drawColor(Color.BLACK);
            canvas.drawBitmap(testimage, testimage.getHeight(), testimage.getWidth(), null);
            canvas.drawBitmap(testimage1, 200, 200, null);
        }
    }
}
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Top

Postby strider2023 » Fri Mar 05, 2010 11:51 am

Solved it :D ...sry fr disturbing!!!
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 18 guests