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

Adobe AIR Development

Reply
New Contributor
GrafixGames
Posts: 5
Registered: ‎07-13-2012
My Device: Playbook
My Carrier: Vodafone

Saving jpeg into playbook

Hello,

 

I tried using jpegEncoder to save image and used File and FileStream to save that encoded jpeg to playbook. 

here's the code that i used.

 

var storage:File = File.userDirectory.resolvePath("shared/photos/PaintBook");
	if(!storage.exists)
	{
		storage.createDirectory();
	}
	
	var file:File;
	
	do
	{
		file = File.userDirectory.resolvePath("shared/photos/PaintBook/Image"+num+".jpeg");
		num++;
		
	}while(file.exists)
	
	var bmd:BitmapData = new BitmapData(canvasWidth, canvasHeight);
	
	bmd.draw(stage);
	
	var jpegEncoder:JPEGEncoder = new JPEGEncoder(Quality);
	var byteArray:ByteArray = jpegEncoder.encode(bmd);
	var stream:FileStream = new FileStream();
	
	stream.open(file, FileMode.WRITE);
	stream.writeBytes(byteArray);
	stream.close();

 

In some reviews of PaintBook, users says that they are unable to save the image i.e image does not appear under

/shared/photos/PaintBook folder. I tested the code on many playbooks and the code runs fine on them.

 

I downloaded a sample app from BB github. it has a code as follows

 

var bitmapData:BitmapData = new BitmapData(1024,600);
			bitmapData.draw(appInstance.mainMovieClip);
			var jpegEncoder:JPEGEncoder = new JPEGEncoder();
			var byteArray:ByteArray=jpegEncoder.encode(bitmapData);
			var currentDate:Date  = new Date();
			var name:File = File.userDirectory.resolvePath(File.documentsDirectory.resolvePath("Signature-Image"+currentDate.toString()+".jpg").nativePath);
			var file:FileStream = new FileStream();
			file.open(name, FileMode.WRITE);
			file.writeBytes(byteArray);
			file.close();

 

The problem is this code does not saves images on my playbook i.e i am unable to see the saved image under any folder. It is a sample app from blackberry that means it should have worked on their playbook

 

Why is it so that code works on some playbook and not on others. Which directory should i use to save images so it works on all playbook?

Developer of
PaintBook and SwitchBalls
Please use plain text.
Regular Contributor
Vemilyus
Posts: 54
Registered: ‎03-21-2011
My Device: 1st Gen BlackBerry PlayBook 16GB (Gift from RIM :D)
My Carrier: WiFi

Re: Saving jpeg into playbook

You have to save the file in the "camera" folder or a sub folder of it. That way it will show up in the camera roll.
This is a signature. Don't expect anything fancy, for I would use an image if I could. But I can't, so cope with it...
Please use plain text.
New Contributor
GrafixGames
Posts: 5
Registered: ‎07-13-2012
My Device: Playbook
My Carrier: Vodafone

Re: Saving jpeg into playbook

By that images will be saved under Camera folder, I want to make a new folder and save it under that folder
Developer of
PaintBook and SwitchBalls
Please use plain text.
Regular Contributor
Vemilyus
Posts: 54
Registered: ‎03-21-2011
My Device: 1st Gen BlackBerry PlayBook 16GB (Gift from RIM :D)
My Carrier: WiFi

Re: Saving jpeg into playbook

That you can do. But only the first level of sub folders will be displayed seperately. Content in sub folders of sub folders will be treated and displayed as content in the first sub folder.
This is a signature. Don't expect anything fancy, for I would use an image if I could. But I can't, so cope with it...
Please use plain text.
New Contributor
GrafixGames
Posts: 5
Registered: ‎07-13-2012
My Device: Playbook
My Carrier: Vodafone

Re: Saving jpeg into playbook

There wont be any subfolders inside that folder.

suppose I make a folder "PaintBook " under "photos". Then all the images will be saved under "PaintBook" folder.

But still this does not explain that why some users are saying that they cant save the image whereas others are able to save it.
Developer of
PaintBook and SwitchBalls
Please use plain text.
New Contributor
GrafixGames
Posts: 5
Registered: ‎07-13-2012
My Device: Playbook
My Carrier: Vodafone

Re: Saving jpeg into playbook

Can we change the permission to write on disk after installing the app?

I think this might have to do something with write permission.

My app is getting down rated because of this silly problem.
Developer of
PaintBook and SwitchBalls
Please use plain text.
Regular Contributor
Vemilyus
Posts: 54
Registered: ‎03-21-2011
My Device: 1st Gen BlackBerry PlayBook 16GB (Gift from RIM :D)
My Carrier: WiFi

Re: Saving jpeg into playbook

The only solution would be to provide a new version with updated permissions. There is no way to change the application permissions after installation.
This is a signature. Don't expect anything fancy, for I would use an image if I could. But I can't, so cope with it...
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Saving jpeg into playbook

You need to set your app permission to the allow you to write to the shared area. You then need to check that each time before you try to write to that area since the user can change the app permission after it has been installed (check document file existence). You cannot change file level permission unless you write an ANE (assuming POSIX calls are allow to chmod).
Please use plain text.
New Contributor
GrafixGames
Posts: 5
Registered: ‎07-13-2012
My Device: Playbook
My Carrier: Vodafone

Re: Saving jpeg into playbook

So everytime before writing a file i should check if the user has disabled the permission, if so then ask user to enable the permission?

How can i do that without writing an ANE?
Developer of
PaintBook and SwitchBalls
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Saving jpeg into playbook

Psedo code:
if( !File.documentsDirectory.exists )
{
// show alert
return;
}
Please use plain text.