Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: How to fetch image from device to bitmap

Here is the code

 

public void selectionDone(String str) {
			
			EncodedImage ei = null;
			FileConnection fconn = null;
			InputStream is = null;
			String orientation = null;
			try {
				fconn = (FileConnection) Connector.open(str, Connector.READ);
				is = fconn.openInputStream();
				ei = EncodedImage.createEncodedImage(IOUtilities.streamToBytes(is),
						0, -1);
				String[] data = ei.getMetaData().getKeys();
				for (int i = 0; i < data.length; i++)
					System.out.println("Meta Keys : " + data[i] + " :::: "
							+ ei.getMetaData().getKeyValue(data[i]));
				
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (is != null) {
					try {
						is.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				if (fconn != null) {
					try {
						fconn.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			int angle = 270;
			
			Bitmap rot = new Bitmap(height, width);

			ei.getBitmap().scaleInto(rot, Bitmap.FILTER_LANCZOS,
					Bitmap.SCALE_TO_FIT);
			bgBitmap=ImageManipulator.rotate(rot, angle);
			Background bg = BackgroundFactory
					.createBitmapBackground(bgBitmap);
			setBackground(bg);
			invalidate();
		}

 

 Thanks

Abhinav Tyagi

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Highlighted
Developer
Posts: 16,750
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to fetch image from device to bitmap

don't do blocking code (like a file connection) on the event thread.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: How to fetch image from device to bitmap

Hi Simon,

 

Please explain. I didn't get your point Smiley Sad

Do I need to change something?

 

Thanks

Abhinav Tyagi

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Developer
Posts: 16,750
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to fetch image from device to bitmap

this video should help you:
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

if you do I/O on the event thread it can be blocked, this means your app becomes unresponsive and the OS will kill it with the message "appxxx not responding, process terminated".
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: How to fetch image from device to bitmap

Thanks Simon,

 

When I click on image to load into my app, it takes 1-2 sec to load.

That means I am blocking my event thread?

I was just going to implement activity indicator for that

 

Thanks

Abhinav Tyagi

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot