Image viewer

Tutorials with advanced 'difficulty' and more Lines of Code.

Image viewer

Postby Beneesh » Fri Apr 09, 2010 8:02 am

Hi,
Iam currently working on picture viewer.Don't copy and paste this code just try to understand what is done and try to build from this code.






public class ImageViewer extends Activity {


ImageView iv;
ScrollView sv;
HorizontalScrollView hv;
LinearLayout lv;
RelativeLayout rl;

float zoom = 1.0f;
int angle=0;
public static Drawable img;

public static Bitmap resizedBitmap;
public static String f;
// private ArrayList<String> ImageList = new ArrayList<String>();


ImageButton bt1;
ImageButton bt2;
ImageButton bt3;
ImageButton bt4;


float scale=1.0f;

Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
int w;
int h;
int po;
String intent;
public String imagepath;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_view);
// iv=(ImageView)findViewById(R.id.iv);
sv=(ScrollView)findViewById(R.id.scroll);
sv.layout(10,10,101,10);
//hv=(HorizontalScrollView)findViewById(R.id.hv);
rl=(RelativeLayout)findViewById(R.id.rl);

iv=new ImageView(ImageViewer.this);
iv.setVerticalScrollBarEnabled(true);
iv.setClickable(true);
rl.setGravity(Gravity.CENTER);


Intent i=getIntent();
po= i.getIntExtra("POSITION", 0);
intent=i.getStringExtra("FILE_PATH");
// ImageList =i.getStringArrayListExtra("ImageList");
System.out.println("The intent is"+intent);
bt1=(ImageButton)findViewById(R.id.image1);
bt2=(ImageButton)findViewById(R.id.image2);
bt3=(ImageButton)findViewById(R.id.image3);
bt4=(ImageButton)findViewById(R.id.image4);
Bitmap bitmapOrg = BitmapFactory.decodeFile(Gallary.path);

Matrix matrix = new Matrix();
matrix.postScale(scale,scale);
resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
bitmapOrg.getWidth(), bitmapOrg.getHeight(), matrix, true);
//BitmapDrawable bmd=new BitmapDrawable(bitmapOrg);
// iv.setImageDrawable(bmd);
iv.setImageBitmap(resizedBitmap );

iv.setScaleType(ScaleType.CENTER);


sv.addView(iv);
sv.setVerticalScrollBarEnabled(true);




bt1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
zoomIn();
}
});

bt2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
zoomOut();
}
});
bt3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
rotateLeft();
}
});
bt4.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
rotateRight();
}
});



}

public void zoomIn()
{
//Bitmap bitmapOrg = BitmapFactory.decodeFile(f);
//int width = bitmapOrg.getWidth();
//int height = bitmapOrg.getHeight();
int width = ImageViewer.resizedBitmap.getWidth();
int height = ImageViewer.resizedBitmap.getHeight();
zoom=zoom+0.1f;

float scaleWidth = zoom;
float scaleHeight = zoom;
try{
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(angle);
// Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg,0,0, width, height, matrix, true);
Bitmap resizedBitmap = Bitmap.createBitmap(ImageViewer.resizedBitmap,0,0, width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
iv.setScaleType(ScaleType.FIT_CENTER);
// iv.layout(0, 0, 0, 0);
iv.setImageDrawable(bmd);

}
catch(final java.lang.OutOfMemoryError e)
{
System.gc();
}

}
public void zoomOut()
{
//Bitmap bitmapOrg = BitmapFactory.decodeFile(f);
//int width = bitmapOrg.getWidth();
// int height = bitmapOrg.getHeight();
zoom=zoom-0.1f;
if(zoom<=0.1f)
{
zoom=zoom+0.1f;
}

float scaleWidth = zoom;
float scaleHeight = zoom;
try{
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(angle);

// Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg,0,0, width, height, matrix, true);
Bitmap resizedBitmap = Bitmap.createBitmap(ImageViewer.resizedBitmap,0,0, width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
iv.setImageDrawable(bmd);
iv.setBackgroundColor(Color.WHITE);

iv.setScaleType(ScaleType.FIT_CENTER);

iv.setVerticalScrollBarEnabled(true);
iv.setHorizontalScrollBarEnabled(true);
}
catch(final java.lang.OutOfMemoryError e)
{
System.gc();
}
}

public void rotateLeft()
{
int width = ImageViewer.resizedBitmap.getWidth();
int height = ImageViewer.resizedBitmap.getHeight();
angle=angle+270;
float scaleWidth =zoom;
float scaleHeight = zoom;

Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(angle);
// Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
// width, height, matrix, true);
Bitmap resizedBitmap= Bitmap.createBitmap(ImageViewer.resizedBitmap, 0, 0,
width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

iv.setImageDrawable(bmd);
// iv.layout(0,0,0,0);
iv.setBackgroundColor(Color.WHITE);
iv.setScaleType(ScaleType.CENTER);

}
public void rotateRight()
{
int width = ImageViewer.resizedBitmap.getWidth();
int height = ImageViewer.resizedBitmap.getHeight();
angle=angle+90;
float scaleWidth = zoom;
float scaleHeight = zoom;

Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(angle);
Bitmap resizedBitmap= Bitmap.createBitmap(ImageViewer.resizedBitmap, 0, 0,
width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
iv.setImageDrawable(bmd);
iv.setBackgroundColor(Color.WHITE);
iv.setScaleType(ScaleType.CENTER);

}

}





[font=Arial Black] [/font] my applications functionalities are working fine...but with a small problem.....the image view is displaying contents in the top left corner of the window.....I added android:layout_gravity="center" to display the image view in the middle. but when the picture is zoomed the bottom and left sides are clippped....if any body give me some suggestions? [font=Arial] [/font]
Last edited by Beneesh on Thu May 06, 2010 9:48 am, edited 4 times in total.
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Top

picture viewer

Postby Beneesh » Wed Apr 28, 2010 5:10 am

Hi ,
I solved the issue , try to place the buttons inside a linear layout and adjust layout gravity that will work.
So anybody who wanted to develop a pictureviewer take this ass a sample code.


Thanks in advance,
Beneesh
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Postby Beneesh » Tue May 04, 2010 10:02 am

hi,

if anybody need help in creating a picture viewer approach me.
Thanks in advance,
Beneesh
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Re: Image viewer

Postby Dhr » Wed Sep 08, 2010 7:03 am

I am new in Android.
So, If I want to put Thumbnails in any imageViewer, then how can I do that?
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Image viewer

Postby Dhr » Wed Sep 08, 2010 7:08 am

I am new in Android.
So, If I want to put Thumbnails in any imageViewer, then how can I do that?
Last edited by Dhr on Wed Sep 08, 2010 9:12 am, edited 1 time in total.
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Image viewer

Postby Beneesh » Wed Sep 08, 2010 7:35 am

Can u be little more specific......on the task u have to do..
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Top

Re: Image viewer

Postby Dhr » Wed Sep 08, 2010 8:01 am

I would like to develop this kind of image viewer in that the Images can be view as like a Thumbnails.
and also it has the ability to view professional RAW formats i.e. RAW image and also ability to backup all/some images to main memory.
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Image viewer

Postby Dhr » Wed Sep 08, 2010 9:11 am

Hello,

Whats the Gallary.path?
What will happen with this code?

Can anyone explain?
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Image viewer

Postby Beneesh » Wed Sep 08, 2010 10:42 am

By passing a images to gallery we can display images thumnail format. also images are scrollable. Wecan select particular image for viewing this.
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Re: Image viewer

Postby Dhr » Wed Sep 08, 2010 11:21 am

But what is Gallary??
Is it a folder's name in which images are stored on Eclipse?

can you give me the exact code and how will it perform because I am stuck at here.
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Image viewer

Postby Beneesh » Wed Sep 08, 2010 11:31 am

k
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Re: Image viewer

Postby Beneesh » Wed Sep 08, 2010 11:35 am

This is for calling gallery class


filePath=FindImages.ImagePath.get(0).toString();
intent = new Intent(GalleryTraverse.this,Gallary.class);
intent.putExtra("FILE_PATH","GalleryTraverse" );
startActivity(intent);
finish();
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Re: Image viewer

Postby Dhr » Wed Sep 08, 2010 11:39 am

ok so we have to create one class which has a name gallery.
is it right??

and in that class have to wirte this code.
Is it true?
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Image viewer

Postby Beneesh » Wed Sep 08, 2010 12:00 pm

yes......I think this code is available...just search in google that's better....
Beneesh
Developer
Developer
 
Posts: 26
Joined: Tue Apr 06, 2010 8:18 am
Location: Kerala,India

Re: Image viewer

Postby Dhr » Wed Sep 08, 2010 12:10 pm

Hey buddy,

This code is not working. It gives me an error.
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Top
Next

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests