Sunday, 15 July 2012

Bitmap to imageview in android -



Bitmap to imageview in android -

i getting next error when seek set bitmap object imageview. "imageview2 cannot resolved variable" line : mimg = (imageview) findviewbyid(r.id.(imageview2));

code :

package com.example.ocr01; import android.os.bundle; import android.app.activity; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.graphics.color; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //setting button , listener button button = (button)findviewbyid(r.id.button1); button.setonclicklistener((onclicklistener) this); } public void onclick(view v) { // when button clicked } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_main, menu); homecoming true; } //converting image bitmap /*public static bitmap getbitmapfromurl(string xxx) { seek { url url = new url(src); httpurlconnection connection = (httpurlconnection) url.openconnection(); connection.setdoinput(true); connection.connect(); inputstream input = connection.getinputstream(); bitmap mybitmap = bitmapfactory.decodestream(input); homecoming mybitmap; } grab (ioexception e) { e.printstacktrace(); homecoming null; } }*/ void create_bitmap(){ //creating bitmap bitmap source = bitmapfactory.decoderesource(getresources(), r.drawable.image1); //calling dogreyscale dogreyscale(source); } public static void dogreyscale(bitmap src) { // constant factors final double gs_red = 0.299; final double gs_green = 0.587; final double gs_blue = 0.114; // create output bitmap bitmap bmout = bitmap.createbitmap(src.getwidth(), src.getheight(), src.getconfig()); // pixel info int a, r, g, b; int pixel; // image size int width = src.getwidth(); int height = src.getheight(); // scan through every single pixel for(int x = 0; x < width; ++x) { for(int y = 0; y < height; ++y) { // 1 pixel color pixel = src.getpixel(x, y); // retrieve color of channels = color.alpha(pixel); r = color.red(pixel); g = color.green(pixel); b = color.blue(pixel); // take conversion 1 single value r = g = b = (int)(gs_red * r + gs_green * g + gs_blue * b); // set new pixel color output bitmap bmout.setpixel(x, y, color.argb(a, r, g, b)); } } //converting bitmap object show in imageview2 imageview mimg; mimg = (imageview) findviewbyid(r.id.(imageview2)); mimg.setimagebitmap(bmout); } }

xml same :

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" > <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textview1" android:layout_centerhorizontal="true" android:src="@drawable/image1" /> <imageview android:id="@+id/imageview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_below="@+id/imageview1" android:src="@drawable/ic_launcher" /> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:text="button" /> </relativelayout>

nb : first time developer trying semester project. kind of help welcomed.

try this:

} //converting bitmap object show in imageview2 imageview mimg; mimg = (imageview) findviewbyid(r.id.imageview2); mimg.setimagebitmap(bmout); }

instead of this:

} //converting bitmap object show in imageview2 imageview mimg; mimg = (imageview) findviewbyid(r.id.(imageview2)); mimg.setimagebitmap(bmout); }

android

No comments:

Post a Comment