erezposner
Lurker
I'm Having problem with a program.
I try to load a pic from sd , and changing its colors.
and then display it.
when the debbuger gets to this line:
myBitmap.setPixels(pix, 0, w, 0, 0, w, h);
my program stops.
pls help!
my code.
package tamp.image.erez;
import java.io.File;
import tamp.image.erez.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class TempimageActivity extends Activity {
Bitmap myBitmap;
ImageView myimage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File imageFile = new File("/sdcard/temp-wlocker-wallpaper.png");
if (imageFile.exists())
{
myBitmap = BitmapFactory.decodeFile("/sdcard/RefPicture.jpg");
myimage = (ImageView) findViewById(R.id.my_image_view);
int h=myBitmap.getHeight();
int w=myBitmap.getWidth();
int[] pix = new int[w * h];
myBitmap.getPixels(pix, 0, w, 0, 0, w, h);
int index = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
int r = (pix[index] >> 16) & 0xff;
int g = (pix[index] >> 8) & 0xff;
int b = pix[index] & 0xff;
r = Math.max(0, Math.min(255, r + 10));
g = Math.max(0, Math.min(255, g + 10));
b = Math.max(0, Math.min(255, b + 10));
pix[index] = 0xff000000 | (r << 16) | (g << 8) | b;
}
index++;
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
myBitmap.setPixels(pix, 0, w, 0, 0, w, h);
myBitmap = null;
myBitmap = bitmap;
pix = null;
if (myimage != null)
{
myimage.setImageBitmap(myBitmap);
}
}
}
}
I try to load a pic from sd , and changing its colors.
and then display it.
when the debbuger gets to this line:
myBitmap.setPixels(pix, 0, w, 0, 0, w, h);
my program stops.
pls help!
my code.
package tamp.image.erez;
import java.io.File;
import tamp.image.erez.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class TempimageActivity extends Activity {
Bitmap myBitmap;
ImageView myimage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File imageFile = new File("/sdcard/temp-wlocker-wallpaper.png");
if (imageFile.exists())
{
myBitmap = BitmapFactory.decodeFile("/sdcard/RefPicture.jpg");
myimage = (ImageView) findViewById(R.id.my_image_view);
int h=myBitmap.getHeight();
int w=myBitmap.getWidth();
int[] pix = new int[w * h];
myBitmap.getPixels(pix, 0, w, 0, 0, w, h);
int index = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
int r = (pix[index] >> 16) & 0xff;
int g = (pix[index] >> 8) & 0xff;
int b = pix[index] & 0xff;
r = Math.max(0, Math.min(255, r + 10));
g = Math.max(0, Math.min(255, g + 10));
b = Math.max(0, Math.min(255, b + 10));
pix[index] = 0xff000000 | (r << 16) | (g << 8) | b;
}
index++;
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
myBitmap.setPixels(pix, 0, w, 0, 0, w, h);
myBitmap = null;
myBitmap = bitmap;
pix = null;
if (myimage != null)
{
myimage.setImageBitmap(myBitmap);
}
}
}
}