iOS app crashes while converting multiple images to base64 - ios

The app has a feature of capturing multiple photos and uploading it to the server. When I loop through 100 images and convert it to base64, it works fine. But if I increase the number of images then it crashes, it doesn't go in the catch block. Below is the code snippet:
List<UIImage> capturedImage= new List<UIImage>();
foreach (var photo in capturedImage) {
var photoImage = photo;
using (NSData imgData = photoImage.AsJPEG(0.5f)) {
var strinng = imgData.GetBase64EncodedString(NSDataBase64EncodingOptions.None);
imageBase64.Add(strinng);
}
}

Related

Images shown rotated in Codename One

I'm developing a Codename One app for iOS.
I gave the user the option to take pictures or to load them from the gallery of the device. After that, the app shows pictures in labels (encapsulated in a BoxLayout).
When I take pictures in portrait mode, everything perfectly works, but when I take pictures in landscape mode, that picture is shown rotated (a 90° rotation).
Here is the code:
String filePath = Capture.capturePhoto();
if (filePath != null) {
try {
Image img = Image.createImage(filePath);
if (img != null){
setImageToContainer(img);
}
}
catch (IOException err) {
ToastBar.showErrorMessage("Problemi con le immagini: " + err.getMessage());
completeImageName = null;
fileImageName = null;
}
}
private void setImageToContainer(Image img){
Label imgLbl = new Label();
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage p = FontImage.createMaterial(FontImage.MATERIAL_PORTRAIT, s);
EncodedImage placeholder = EncodedImage.createFromImage(p.scaled(p.getWidth() * 3, p.getHeight() * 4), false);
imgLbl.setIcon(placeholder);
list.add(imgLbl);
//Scalo l'immagine
if(img.getWidth() > imgLbl.getParent().getWidth())
img = img.scaledWidth(imgLbl.getParent().getWidth());
if(img.getHeight()> imgLbl.getParent().getHeight())
img = img.scaledHeight(imgLbl.getParent().getHeight());
imgLbl.setIcon(img);
list.repaint();
}
Reading that answer, I understood Image.createImage(filePathToImage) method takes in account EXIF data, in order to properly rotate the image.
How can I solve my problem? Is there a way to get EXIF data?

Swift: UIImageJPEGRepresentation return nil while looping

I've been searching for this problem for a few days already. Still no answer. I'm trying to send multiple images to the server, so, I need to convert the uiimage to nsdata first. But the nsdata seem to be a nil, but the 1st image always successful to be convert. Here is the code:
for image in images {
var imageTemp: NSData?
if let image_data = UIImageJPEGRepresentation(image, 1) {
imageTemp = image_data
}
if imageTemp == nil
{
print("nil")
return
}
i = i + 1;
}

Xamarin iOS ALAssetsLibrary WriteVideoToSavedPhotosAlbum doesn't save to library

I am writing an iOS application using Xamarin and am having an issue getting videos to save to my photo library. I am using the WriteVideoToSavedPhotosAlbum method of the ALAssetsLibrary (code below), but the video is never saved. I do no receive an error, but I also do not receive an asset URL in the completion block either.
Does anyone have any idea what could be going on here?
var url = NSUrl.FromFilename (this.FilePath);
ALAssetsLibrary library = new ALAssetsLibrary ();
library.WriteVideoToSavedPhotosAlbum (url, delegate(NSUrl u, NSError e)
{
if (e != null)
{
new UIAlertView ("Error", "Unable to save video to library", null, "Ok").Show();
}
});
One thing to note is the FilePath value is a video stored in the applications document directory.
Thanks
One thing to note is the FilePath value is a video stored in the applications document directory? What you are looking for exactly? as WriteVideoToSavedPhotosAlbum is use to store video capture using camera because directly we can not get its url so we have to store video or image captured using camera to device first then we can get its url and other information using ALAssetsLibrary
I have done like this and its working for me hope this might help you:
ALAssetsLibrary library = new ALAssetsLibrary();
library.WriteImageToSavedPhotosAlbum(originalImage.CGImage, meta, (assetUrl, error) =>
{
library.AssetForUrl(assetUrl, delegate (ALAsset asset)
{
ALAssetRepresentation representation = asset.DefaultRepresentation;
if (representation != null)
{
string fileName = representation.Filename != null ? representation.Filename : string.Empty;
var filePath = assetUrl.ToString();
var extension = filePath.Split('.')[1].ToLower();
var mimeData = string.Format("image/{0}", extension);
var mimeType = mimeData.Split('?')[0].ToLower();
var documentName = assetUrl.Path.ToString().Split('/')[1];
}
}, delegate (NSError err) {
Console.WriteLine("User denied access to photo Library... {0}", err);
});
});

How to get the file path to a CameraRoll loaded image?

I would like to get the file path of an image that got loaded over the CameraRoll with the code below.
The app runs on an iPhone with iOS 8 an it's build with Adobe Air 15.
var loaderCameraRoll:Loader
var deviceCameraRoll:CameraRoll
function loadImageFromCameraRoll(e:Event=null):void {
deviceCameraRoll = new CameraRoll();
deviceCameraRoll.addEventListener(MediaEvent.SELECT, onSelectCameraRoll);
deviceCameraRoll.browseForImage();
}
function onSelectCameraRoll(event:MediaEvent):void {
var promise:MediaPromise = event.data as MediaPromise;
loaderCameraRoll = new Loader()
loaderCameraRoll.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedCameraRoll);
loaderCameraRoll.loadFilePromise(promise);
}
function onLoadedCameraRoll(event:Event):void {
trace("Loaded - File path: ?")
}

Adobe AIR Mobile on iOS - processing text very slow

I am writing an iOS app in Flash Builder 4.6 that will need to process a large text file. So far, I am just trying to get the version information from the file, a simple task that runs very fast in the simulator but takes a very long time (on the order of 10 seconds) on my iPad 2.
As the file is large (about 11MB), I am trying to only read far enough into the file to get the version data. Is it possible that the filestream loads the whole file into memory anyway? If so, how do I avoid that?
Note that the code works correctly, and displays the correct version info.
Any advice on how to speed it up would be greatly appreciated.
The file being processed can be found here: http://oanda.sca.org:80/oanda.db
The code is as follows:
Calling code:
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
var DT:DatabaseTools = new DatabaseTools();
var version:String;
//Get version information from local file:
version = DT.GetLocalVer("oanda.db");
lblLclVer.text=version;
}
Actual function:
public function GetLocalVer(fileName:String):String
{
var out:ByteArray = new ByteArray();
var line_Out:String;
var char:int;
var line:ByteArray = new ByteArray();
var stream:FileStream = new FileStream();
var file:File = File.documentsDirectory.resolvePath(fileName);
var lineString:String;
var result:String = "Error";
stream.open(file,FileMode.READ);
var found:Boolean=false;
while((stream.bytesAvailable > 0) && !found)
{
char=stream.readByte();
if(String.fromCharCode(char) == "\n")
{
//reset the line
out=line;
line = new ByteArray();
//process the line to see if its the version info.
lineString=out.toString(); //since the version line never has UTF characters, convert it to a regular string
if(lineString.length > 25) //Any line shorter than this can't be the version line
{
var startOfLine:String = lineString.substr(0,17);
if(startOfLine == " ||C|Last update:")
{
result = lineString.substr(19,6);
found = true;
}
}
}
else
{
line.writeByte(char);
}
}
stream.close();
return result;
}
Thanks.

Resources