package name : com.myandroid.comImage;
Activity Name :ImageCompActivity
Target::2.1
public class ImageCompActivity extends Activity {
Bitmap bm1,bm2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res=ImageCompActivity.this.getResources();
// take image from the drawable folder and typecast as a Drawable//
Drawable dra1=res.getDrawable(R.drawable.ic_launcher_i);
Drawable dra2=res.getDrawable(R.drawable.ic_launcher);
// convert bitmap //
bm1 = ((BitmapDrawable)dra1).getBitmap();
bm2 = ((BitmapDrawable)dra2).getBitmap();
System.out.println(" SAve To Image :"+bm1);
System.out.println(" SAve To Image :"+bm2);
if(imagesAreEqual(bm1,bm2)) // use imagesAreEqual() mathod for check two iamge equal or not //
{
System.out.println(" Two Image are Equal");
}
else
{
System.out.println(" Two Image are Equal");
}
}
boolean imagesAreEqual(Bitmap i1, Bitmap i2)
{
if (i1.getHeight() != i2.getHeight())
return false;
if (i1.getWidth() != i2.getWidth()) return false;
for (int y = 0; y < i1.getHeight(); ++y)
for (int x = 0; x < i1.getWidth(); ++x)
if (i1.getPixel(x, y) != i2.getPixel(x, y)) return false;
return true;
}
}
/////////////////////////////// XML////////////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
////////////////////////////////
take two image ic_launcher.png and ic_launcher_i.png
Activity Name :ImageCompActivity
Target::2.1
public class ImageCompActivity extends Activity {
Bitmap bm1,bm2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res=ImageCompActivity.this.getResources();
// take image from the drawable folder and typecast as a Drawable//
Drawable dra1=res.getDrawable(R.drawable.ic_launcher_i);
Drawable dra2=res.getDrawable(R.drawable.ic_launcher);
// convert bitmap //
bm1 = ((BitmapDrawable)dra1).getBitmap();
bm2 = ((BitmapDrawable)dra2).getBitmap();
System.out.println(" SAve To Image :"+bm1);
System.out.println(" SAve To Image :"+bm2);
if(imagesAreEqual(bm1,bm2)) // use imagesAreEqual() mathod for check two iamge equal or not //
{
System.out.println(" Two Image are Equal");
}
else
{
System.out.println(" Two Image are Equal");
}
}
boolean imagesAreEqual(Bitmap i1, Bitmap i2)
{
if (i1.getHeight() != i2.getHeight())
return false;
if (i1.getWidth() != i2.getWidth()) return false;
for (int y = 0; y < i1.getHeight(); ++y)
for (int x = 0; x < i1.getWidth(); ++x)
if (i1.getPixel(x, y) != i2.getPixel(x, y)) return false;
return true;
}
}
/////////////////////////////// XML////////////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
////////////////////////////////
take two image ic_launcher.png and ic_launcher_i.png
No comments:
Post a Comment