On Fri, Dec 16, 2011 at 8:29 PM, skink <[email protected]> wrote:
>
>
> chowdary nani wrote:
> > Hi All,
> > I need help on Image rotate in android for the image which is selected
> in the gallery is displayed on the imageview but while i am trying to
> rotate the image it is rotating all the image with back ground and it is
> rotating the first image in gallery view
>
> > I am developing using below code.
>
public class Gadegets extends Activity {
ImageAdapter imageadapter;
private View view;
Button clipart, text;
private Integer[] mImageIds = { R.drawable.a_1, R.drawable.a_2,
R.drawable.honeycomb };
private int position;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gadgets);
Button cloclrotate = (Button) findViewById(R.id.button_clock);
cloclrotate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
make(90);
}
});
Button anticlock = (Button) findViewById(R.id.button_anti);
anticlock.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
make(-90);
}
});
final ImageView imview = (ImageView) findViewById(R.id.imageView1);
Gallery g = (Gallery) view.findViewById(R.id.galle);
imageadapter = new ImageAdapter(Gadegets.this);
g.setAdapter(imageadapter);
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v,
int position, long id) {
imview.setImageResource(mImageIds[position]);
// setContentView(new Zoom(this));
}
});
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
TypedArray attr = mContext
.obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground,
0);
attr.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup
parent) {
Log.d("eredtgdffhgh", "rdrruyghtyrtytuuurt swathi
naveen");
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(100, 80));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
}
public void make(float x) {
android.util.Log.i("INSIDE MAKE", "inside make");
LinearLayout linLayout = new LinearLayout(this);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
mImageIds[position]);
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200;
int newHeight = 200;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(x);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,
height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
// BitmapDrawable bmd = new BitmapDrawable();
ImageView imageView = new ImageView(this);
imageView.setImageDrawable(bmd);
imageView.setScaleType(ScaleType.CENTER);
linLayout.addView(imageView, new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(linLayout);
android.util.Log.i("GOING OUT MAKE", "going out make");
}
}
please help me i am unable to find where i am going wrong.
Thanks
naveen
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en