DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Extending Java APIs: Add Missing Features Without the Hassle
  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage

Trending

  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Extending Java APIs: Add Missing Features Without the Hassle
  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Connect pictures on Android (Jigsaw puzzle example)

Connect pictures on Android (Jigsaw puzzle example)

Alex Kizub user avatar by
Alex Kizub
·
Dec. 27, 11 · News
Like (1)
Save
Tweet
Share
14.71K Views

Join the DZone community and get the full member experience.

Join For Free

Few tips how to make pictures on Android more realistic and connect to each other smoothly.

I want to share some experince what I got from my work with Android images when I wrote simple Android appilcation. Here it is in 3 tips:

1) Use Antialiasing option to draw

Unles you want see ugly edges like this

Not using antialiasing

always use Paint.ANTI_ALIAS_FLAG

 However, since we are drawing pictures it's not as simple as drawing lines or pathes. If you simply clipPath no Antialising will help. To make picture really smooth  draw desired path in Antialias mode and then use Xfermode mode and cut your picture through this already Antialising pattern:

	public Bitmap getPuzzlePiece(Path path, Bitmap image) {
		Drawable imageDrawable =  new BitmapDrawable(image);

		RectF rectf = new RectF();
		path.computeBounds(rectf, false);
		path.offset(-rectf.left, -rectf.top);

		Bitmap targetBitmap = Bitmap.createBitmap((int) rectf.width(),
				(int) rectf.height(), Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(targetBitmap);
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		paint.setColor(Color.RED);
		canvas.drawPath(path, paint);
		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
		imageDrawable.setBounds(0, 0, width, height);// add bounds or picture will be blank

		canvas.saveLayer(null, paint, Canvas.ALL_SAVE_FLAG);
		canvas.translate(-rectf.left, -rectf.top);
		imageDrawable.draw(canvas);
		canvas.restore();

		return targetBitmap;
	}

 With such tecnique picture will look a little nicer:

 Antialis image

2) Don't do precise calculations. Leave connections to PATH. 

There is a temptation to calculate all points precisely and make picture perfect. However, remeber, firts of all this is still computer only and it can't do precise calculation even with enourmous resorces. Another thought is that, after all, pictire is in pixels and so it will be never precise by itself.

Let's take example of some critical point of some connection on the drawing path. Assuming that calculation of intersection was wrong (for any reason mintioned above) and resul is blue dot on the left side then it could be some unwanted extra pieces on this path like trainlge. But, if you stop your path earlier and start next element later then path itslef will add not unwanted triangle but real and, probably, not bad connection. See the right connection on the circle:

 Critical points of PATH connection

On real picture it will look pretty nice:

 Real connection on the picture

 

3) Overlap

Since picture is always not precise make each piece a little bigger so it will overlap other pieces and it will be no gaps between them.

Even final connected picture looks solid in reality there is small invisible overlap:

 Pieces overlap

Here is application itself on the Android Market:

 https://market.android.com/details?id=com.puzzle.jigsaw

Android (robot)

Opinions expressed by DZone contributors are their own.

Trending

  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Extending Java APIs: Add Missing Features Without the Hassle
  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: