gayathri suhen

Greenhorn
+ Follow
since Nov 19, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by gayathri suhen

Ulf Dittmer wrote:It sort of looks like the code does something like that. But the "result" array is not used - you need to construct a Bitmap from it and display that.


Alright but what code am i to add in, and where?
9 years ago
[quote=Ulf Dittmer]What does the code do you now? At which point are you struggling to make the required changes? [/quote]

Curently, i am only able to pick an image and display it. However i want to know what do i need to add to display the image which is converted to grayscale?
9 years ago
Hi guys, my project is due in 2 days. I would really appreciate if someone can help me with converting the image I selected in the gallery into grayscale and return it into the imageview. Thanks in advance!

public class SelectImageActivity extends Activity implements OnClickListener {

// Image loading result to pass to startActivityForResult method.
private static int LOAD_IMAGE_RESULTS = 1;

// GUI components
private Button button; // The button
private ImageView image;// ImageView

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_image);

// Find references to the GUI objects
button = (Button)findViewById(R.id.button);
image = (ImageView)findViewById(R.id.image);

// Set button's onClick listener object.
button.setOnClickListener(this);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

// Here we need to check if the activity that was triggers was the Image Gallery.
// If it is the requestCode will match the LOAD_IMAGE_RESULTS value.
// If the resultCode is RESULT_OK and there is some data we know that an image was picked.
if (requestCode == LOAD_IMAGE_RESULTS && resultCode == RESULT_OK && data != null) {
// Let's read picked image data - its URI
Uri pickedImage = data.getData();
// Let's read picked image path using content resolver
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
Bitmap bitmap1=BitmapFactory.decodeFile(imagePath);
int threshold=100;
int [][] result= new int [bitmap1.getWidth()][bitmap1.getHeight()];
for (int x=0; x<bitmap1.getWidth();x++)
{
for (int y=0; y<bitmap1.getHeight();y++)
{
if (bitmap1.getPixel(x, y)>threshold)

result[x][y]=255;
else
result[x][y]=0;

}


}


// Now we need to set the GUI ImageView data with data read from the picked file.
image.setImageBitmap(BitmapFactory.decodeFile(imagePath));

// At the end remember to close the cursor or you will end with the RuntimeException!
cursor.close();
}
}
@Override
public void onClick(View v) {
// Create the Intent for Image Gallery.
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

// Start new activity with the LOAD_IMAGE_RESULTS to handle back the results when image is picked from the Image Gallery.
startActivityForResult(i, LOAD_IMAGE_RESULTS);
}




}

9 years ago