Security Error when trying to load ByteArray from mediaPromise - ios

in a mobile application i need to send an image which the user either took with the camera or picked from a cameraroll.
I am using the starling framework and feathersUI ( although i think this does not matter to problem )
When the mediapromise is loaded using loadFilePromise i use the following code to deal with the image data:
_mediaLoader = new Loader()
//loading the filePromise from CameraRoll
_mediaLoader.loadFilePromise(_mediaPromise);
_mediaLoader.contentLoaderInfo.addEventListener(starling.events.Event.COMPLETE, onLoadImageComplete);
private function onLoadImageComplete(event:flash.events.Event=null):void {
//creating the starling texture to display the image inside the application
var texture:Texture = Texture.fromBitmapData(Bitmap(_mediaLoader.content).bitmapData, false, false, 1);
//now trying to load the content into a bytearray to send to the server later
var bytes:ByteArray=_mediaLoader.contentLoaderInfo.bytes;
}
the last line of code results in a Security error:
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2121: Security sandbox violation: app:/myapp.swf: http://adobe.com/apollo/[[DYNAMIC]]/1 cannot access . This may be worked around by calling Security.allowDomain.
I tried
Security.allowDomain("*")
as a test
but then i get:
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
As a workaround i write my own png ByteArray inside the Application from the loaders BitmapData using Adobes PNGEncoder Class:
var ba:ByteArray=PNGEncoder.encode(Bitmap(_mediaLoader.content).bitmapData)
But this takes a significant amount of time ...
I also tried the FileReference to load the image but
_mediaPromise.file
and
_mediaPromise.relativePath
are both null.
What am I doing wrong? Or is this a known problem ?
Thanks!

Hello I have found a solution based on a post about the processing of exif data mentioned here: http://blogs.adobe.com/cantrell/archives/2011/10/parsing-exif-data-from-images-on-mobile-devices.html
the crucial code
private function handleMedia(event:MediaEvent):void{
_mediaPromise=event.data as MediaPromise;
_imageBytes=new ByteArray()
var mediaDispatcher:IEventDispatcher = _mediaPromise.open() as IEventDispatcher;
mediaDispatcher.addEventListener(ProgressEvent.PROGRESS, onMediaPromiseProgress);
mediaDispatcher.addEventListener(flash.events.Event.COMPLETE, onMediaPromiseComplete);
};
private function onMediaPromiseProgress(e:ProgressEvent):void{
var input:IDataInput = e.target as IDataInput;
input.readBytes(_imageBytes, _imageBytes.length, input.bytesAvailable);
};
private function onMediaPromiseComplete(e:flash.events.Event):void{
_mediaLoader = new Loader();
_mediaLoader.loadBytes(_imageBytes)
};
works like a charm for me on ipad and iphone.

Related

Requested ChangeOrientation operation for ‘Pdf’ document type is not supported groupdocs merger

I am creating a web application and I am using groupdocs for view pdf and other docs,
in one of the scenario I want to change particular page orientation of pdf document, I found groupdocs merger with a set of code from here and I modified that code with my expectations which is below,
string filePath = #"c:\sample.pdf";
OrientationOptions orientationOptions = new OrientationOptions(OrientationMode.Landscape, new int[] { 3, 4 });
using (Merger merger = new Merger(filePath))
{
merger.ChangeOrientation(orientationOptions);
merger.Save(filePath);
}
but I am getting the below error
Requested ChangeOrientation operation for ‘Pdf’ document type is not
supported
I tried this in groupdocs 21.8 version
I found groupdocs merger with a set of code from here
We cannot reproduce this issue using GroupDocs.Viewer for .NET rotate pages. Have a look at the blow screenshot and the code:
using (Viewer viewer = new Viewer(#"D:/test.pdf"))
{
PdfViewOptions viewOptions = new PdfViewOptions(#"D:/output.pdf");
viewOptions.RotatePage(1, Rotation.On90Degree);
viewer.View(viewOptions);
}
As you are using GroupDocs Viewer API to render/view documents. Please use the above mentioned code. However, this issue exists in GroupDocs.Merger for .NET and we are working on the fix.

Getting IMediaExtension to work with MediaComposition

I was attempting to use Windows Phone Media Extensions sample with MediaComposition:
I'm trying to run InvertTransform from the sample by adding it to MediaComposition on Windows Phone 8:
var composition = new MediaComposition();
var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///videos/test.mp4"));
var clip = await MediaClip.CreateFromFileAsync(file);
clip.VideoEffectDefinitions.Add(new VideoEffectDefinition("InvertTransform.InvertEffect"));
composition.Clips.Add(clip);
This fails, probably because video subtype is MFVideoFormat_NV12 while effect is handling only MFVideoFormat_ARGB32.
How can invert transform be used in this scenario? Does it have to be changed to support MFVideoFormat_NV12 and how best to accomplish this?
Thank you
After doing lot of tests, only way to do this is to handle NV12 format, and convert to and back from RGB, if needed.

How to implement IndexDB in IOS

I am developing a mobile application using phonegap, Initially I have developed using WEBSQL but now I m planning to move it on INDEXDB. The problem is it does not have direct support on IOS , so on doing much R&D I came to know using IndexedDB Polyfil we can implement it on IOS too
http://blog.nparashuram.com/2012/10/indexeddb-example-on-cordova-phonegap.html
http://nparashuram.com/IndexedDBShim/
Can some please help me how to implement this as there are not enough documentation for this and I cannot figure out a any other solution / api except this
I have tested this on safari 5.1.7
Below is my code and Error Image
var request1 = indexedDB.open(dbName, 5);
request1.onsuccess = function (evt) {
db = request1.result;
var transaction = db.transaction(["AcceptedOrders"], "readwrite");
var objectStore = transaction.objectStore("AcceptedOrders");
for (var i in data) {
var request = objectStore.add(data[i]);
request.onsuccess = function (event) {
// alert("am again inserted")
// event.target.result == customerData[i].ssn;
};
}
};
request1.onerror = function (evt) {
alert("IndexedDB error: " + evt.target.errorCode);
};
Error Image
One blind guess
Maybe your dbName contains illegal characters for WebSQL database names. The polyfill doesn't translate your database names in any kind. So if you create a database called my-test, it would try to create a WebSQL database with the name my-test. This name is acceptable for an IndexedDB database, but in WebSQL you'll get in trouble because of the - character. So your database name has to match both, the IndexedDB and the WebSQL name conventions.
... otherwise use the debugger
You could set a break point onto your alert(...); line and use the debugger to look inside the evt object. This way you may get either more information about the error itself or more information to share with us.
To do so, enable the development menu in the Safari advanced settings, hit F10 and go to Developer > Start debugging JavaScript (something like that, my Safari is in a different language). Now open then "Scripts" tab in the developer window, select your script and set the break point by clicking on the line number. Reload the page and it should stop right in your error callback, where you can inspect the evt object.
If this doesn't help, you could get the non-minified version of the polyfill and try set some breakpoints around their open function to find the origin of this error.
You could try my open source library https://bitbucket.org/ytkyaw/ydn-db/wiki/Home. It works on iOS and Android.

Open local pdf file using pdf.js in firefox extension

I am using pdf.js to extract annotations from pdf files in a firefox add-on. Everything works pretty well except opening local pdf files. PDFJS.getDocument('http://...').then(function(pdf) { ... works but PDFJS.getDocument('file:///...').then(function(pdf) { does not.
I am getting this error: Unexpected server response (0) while retrieving PDF ...
Is this a cross-domain issue? I thought that shouldn't be a problem because my code is running from an extension. How can I solve this problem?
Read the file into a Uint8Array and pass it as source to getDocument.
Here is a simplified JS that works for me as illustration only -
You first get the file as array buffer (e.target.result) then convert it to Uint8 array and pass it to PDF.js as data (docInitParams) instead of a URL
var reader = new FileReader();
reader.readAsArrayBuffer(input.files[0]);
reader.onload = function (e) {
var myData = new Uint8Array(e.target.result)
var docInitParams = { data: myData };
PDFJS.getDocument(docInitParams).then(function(pdf) {.....})
}

Monodroid Camera/imageview example

Can someone post an example of how to use the camera, capture the image, preview the image in an image view, compress the image in jpg and upload the bytes to a remote server? The closest I have been able to find is below. We have the camera, and image capture but we need to know how to preview, compress/resize jpg to 640/480px and around 120kb size then upload bytes to a remote server. Thanks to all of you for your help.
http://android-coding.blogspot.com/2010/12/intent-of-mediastoreactionimagecapture.html
Looking at your code there are some things i notice to be wrong:
-[ for the camera functionality ]-
Don't create a file yourself. This is not necessary. Use the ContentResolver.Insert function to give you back a file URI that will contain the picture, just like done here and also take over the isMounted if you want to check if there is external memory present.
You are checking if there's data and then checking if there is a thumbnail. If there's no thumbnail you'll get the full image. That doesn't make sense unless you want to make a thumb of the full version if the thumb is not given back?? Don't you just want to grab the full version or both but not this OR that?
You are retrieving a string value variable to get the URI to the full image? Just save the uri you get from the code in my first point as a property (let's say "myPhotoURI" in the activity class. In the OnActivityResult function that handles your camera intent result just recall that URI and use it as following (Yes, you're seeing it right; i'm not even using the data intent for this just the remembered uri):
Bitmap imageFromCam = MediaStore.Images.Media.GetBitmap(this.ContentResolver, Android.Net.Uri.Parse(myPhotoURI));
To grab an image from the gallery just use the SelectImageFromStorage() function from this question's answer and retrieve the URI of the chosen image in the OnActivityResult check just use:
Android.Net.Uri selectedImageUri = data.ToURI();
That's what worked like a charm for me.
-[sending the data to a webservice ]-
Assuming you're using a WCF or webservice that'll want to receive the image data as a byte array; the approved answer to this question gives a nice example of how to convert your image to an byte array (which is what a WCF webservice wants, anyway)
I think that these directions will get you going.
here is the closest example to date... this brings back Null data when the extra output is used. Still trying to get access to the full image/photo and not a thumbnail.
private void saveFullImage() {
Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
string file = System.IO.Path.Combine(Android.OS.Environment.DirectoryDcim.ToString(), "test.jpg");
var outputFileUri = Android.Net.Uri.Parse(file);
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput, outputFileUri);
StartActivityForResult(intent, TAKE_PICTURE);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null)
{
if (data.HasExtra("data"))
{
var thumbnail = data.GetParcelableArrayExtra("data");
// TODO Do something with the thumbnail
}
}
else
{
var outputFileUri = data.GetParcelableArrayExtra("outputFileuri");
// TODO Do something with the full image stored
// in outputFileUri
}
}
}

Resources