Using Isolated Storage Images in the HubTiles - isolatedstorage

I let the users take images in my app and save the images in the Isolated Storage. I also use HubTiles in my app but the HubTiles use a Uri in their Source property but it can't recognize the isostore:/..... Uris..
Any idea how can I fix this issue?

You are not the only one experiencing that the isostore:/ URIs are not functioning in every place an URI is expected. So it seems like you need to take the more traditional approach and load the image by hand:
// define data array to hold image data to be read from isolated storage
byte[] imageBytes;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
// open image file
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("MyPreviouslySavedImage.jpg", FileMode.Open, FileAccess.Read))
{
// allocate array large enough to hold the whole file
imageBytes = new byte[fileStream.Length];
// read all data to memory
fileStream.Read(imageBytes, 0, imageBytes.Length);
fileStream.Close();
}
}
// create memory stream and bitmap
MemoryStream memoryStream = new MemoryStream(imageBytes);
BitmapImage bitmapImage = new BitmapImage();
// memory stream is source of bitmap
bitmapImage.SetSource(memoryStream);
// finally assign image to hub tile
hubTile1.Source = bitmapImage;
This works well (if there is an image in the isostore of course).

Related

Write depthMap buffer to file (Swift)

I work with the new iPadPro and a LIDAR app and am kinda new to SWIFT5 (normaly working on CordovaApps with minimal native coding needed)
I want to dump the CVPixelBuffer I get for a frame to a .bin file.
I get the buffer like this: let depthMap = frame.sceneDepth!.depthMap
It returns a DepthFloat32 buffer.
After that I lock the address and fetch it:
CVPixelBufferLockBaseAddress(depthMap, CVPixelBufferLockFlags(rawValue: 0))
var addr = CVPixelBufferGetBaseAddress(depthMap)
How can I save these values to a file on my iPad? Would be thankful for any help.
I solved it on my own. Here is my solution in case somebody needs it.
Gather all the necessary values:
let addr = CVPixelBufferGetBaseAddress(depthMap)
let height = CVPixelBufferGetHeight(depthMap)
let bpr = CVPixelBufferGetBytesPerRow(depthMap)
Then I hand the bufferaddress to the Data obj to create a byte buffer in memory --> Data
let data = Data(bytes: addr!, count: (bpr*height))
do {
let filename = getDirectory().appendingPathComponent(timestamp +"_depthbuffer.bin")
try data.write(to: filename)
} catch {
// do smth with errors
}
getDirectory() is a custom function to find the Documents Directory. I can get the created Files from the App Container.
Don't forgett to Lock & unlock the BufferAdress.

Flutter: Picking images as jpg/png instead of heic on iOS

How can I pick images directly as jpg or png on iOS?
If this feature isn't available: How can I convert it very fast and don't have to wait a long time?
Edit: I want to prevent picking .heic because I have to send it to an server, which handles jpg and png and not .heic
Thanks to Mohammad Assad Arshad!
It can be solved by pub.dev/packages/file_picker.
An additional explanation:
https://pub.dev/packages/file_picker allows you to pick files/images etc. and the file type of images is .jpg
https://pub.dev/packages/multi_image_picker allows you to pick images too, but takes the original file format; e.g. .heic, .jpg, .png
i select images with filepicker https://pub.dev/packages/file_picker
FilePickerResult result;
try {
result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['jpeg', 'jpg', 'heic', 'pdf'],
);
} catch (e) {
print('Exep: ****${e}***');
}
now you can check the extention of the file, use the package path.dart as p and package https://pub.dev/packages/heic_to_jpg to convert image to jpeg
File file = File(result.files.first.path);
String fileExtension = p.extension(file.path).replaceAll('.', '');
if (fileExtension == 'heic') {
print('convert to jpeg');
String jpegPath = await HeicToJpg.convert(file.path);
file = File(jpegPath);
fileExtension = 'jpeg';
}
do not forget do the same if you use imagePicker with source camera.
you can use multi_image_picker 4.6.7 to pick image in iOS for HEIC images.

How can i pass a QR code image to apple watch

I have a QR code image in the format xamarin.forms.image created using zxing.
My requirement is to show this QR code on apple watch. this image is saved to a global variable like below
stackQRCode.Children.Add(zXingBarcodeImageView);
App.QRCodeImage = zXingBarcodeImageView
I am trying with wcsessionmanager.But in the UpdateApplicationContext, the image is not getting sent.
anyone with solution? What is the simplest way to achieve this?Thanks in Advance.
The Easiest way to convert a Xamarin Forms Image into a UIImage and vice versa would be byte[] conversion:
UIImage to Byte[]:
byte[] byteArray;
using (NSData imageData = originalImage.AsJPEG())
{
byteArray = new Byte[imageData.Length];
System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, byteArray, 0, Convert.ToInt32(imageData.Length));
}
Byte[] to Xamarin.Forms.ImageSource:
var XamImageSource=ImageSource.FromStream(() => new MemoryStream
(byteArray));
Now the catch is the other way around Xamarin.Forms Image/ImageSource do not expose any API's to directly get the image stream or byte[] from it.(In my Knowledge)
So you can use FFImageLoading instead!!
Which has an API to get the RawImage as follows
FFImageLaoding to byte[]:
var bytes = await ImageView.GetImageAsJpgAsync(); //png method also available
byte[] to UIImage
var data = NSData.FromArray(byteData);
var uiimage = UIImage.LoadFromData(data);

Flutter/Dart overwriting File in getApplicationDocumentsDirectory not working immediately

I'm trying to overwrite a file in my apps temporary directory but for some reason the overwrite is not taking effect until I fully hot restart my app.
I'm trying to set my _pickedImage variable to the new changedImage once it has been copied to the directory, however when using setState it is always keeping the first image that was placed into the directory and not overwriting it each time. So when I display the _pickedImage it will always show the first initial image until i fully restart, once i fully restart the app the change is taking place. The reason for wanting to do this is so that users can effectively change the image if they wish. Hope this makes sense any help would be massively appreciated
var image = await ImagePicker.pickImage(source: source, maxWidth: 800.0);
if (image != null) {
final Directory extDir = await getApplicationDocumentsDirectory();
final String dirPath = '${extDir.path}/image';
if (Directory(dirPath).existsSync()) {
print('it exists');
var dir = new Directory(dirPath);
dir.deleteSync(recursive: true);
if (Directory(dirPath).existsSync()) {
print('still exists');
} else {
//It is getting in here so seemingly its deleting the orignal directory
print('does not exist');
}
}
new Directory(dirPath).createSync(recursive: true);
String path =
'$dirPath/temporaryImage.jpg';
File changedImage = image.copySync(path);`
setState(() {
//this is where the problem lies
_pickedImage = changedImage;
});
Cache is the problem. See issue https://github.com/flutter/flutter/issues/24858
From documentation https://api.flutter.dev/flutter/painting/ImageProvider-class.html
ImageProvider uses the global imageCache to cache images.
You can use
import 'package:flutter/painting.dart'
// to clear specific cache
imageCache.evict(FileImage(processedImage));
// to clear all cache
imageCache.clear();
It did not directly solve issue I had, however, it was the key.

flash.display.Loader class on iOS

Intro - I am working on a iOS game using Flash CS5.5. In my game i am loading a image via the camera roll, and gonna use the image in the gameplay. I want the image to load back in when the user restarts the game.
Question - Is there a way to access such image again without having to open up the camera roll interface.
Can i use the flash.display.Loader class? Is there any special things i need to do or set? Or is there another way?
I've tried just saving the file, given from the MediaEvent dispatched when you select an image.
But i have no luck using the URL given in the loader object. I am using the example from this page as my base: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/CameraRoll.html.
Yes this is possible. You need to save the image into the apps documents directory using the File class with something like this: (this uses the Adobe JPGEncoder class)
f = File.documentsDirectory.resolvePath("logo.jpg");
stream = new FileStream();
stream.open(f, FileMode.WRITE);
j = new JPGEncoder(80);
var bytes:ByteArray = j.encode(visualLogo.bitmapData);
stream.writeBytes(bytes, 0, bytes.length);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();
//I read the file back in to test that it has been successfully written
stream.openAsync(f, FileMode.READ);
stream.addEventListener(Event.COMPLETE, bringBoardOn, false, 0, true);
Then load it back in using something like this:
f = File.documentsDirectory.resolvePath ("logo.jpg");
if (f.exists == true) {
var _urlRequest:URLRequest = new URLRequest(f.url);
loader=new Loader;
loader.load(_urlRequest);
loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{ trace(e) });
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ImageLoaded, false, 0, true);
_urlRequest = null;
}

Resources