I am using the display.capureScreen() to take a picture of the users final score. After that happens, a window pops up showing their coins, score, high score, and the picture that was just captured. When I do this:
screenCap = display.captureScreen(true)
It saves the picture to the photo library because it is set to true. My question is how could I not save this automatically, but only if the user wants to, using a "save picture" button?
You can use display.save(object, filename) to save the display object returned by captureScreen():
local image = display.captureScreen()
image:toBack() -- hide it
... do stuff...
display.save( image, { filename="image.png", isFullResolution=true } )
image:removeSelf() -- no longer need it
image = nil
Image must be in display hierarchy when you save it.
If you want to save to the photo album later, then display.save doesn't give you that option, you have to use display.capture or display.captureBounds. Example:
local image = display.captureScreen()
image:toBack() -- hide it
... do stuff...
local capture = display.capture( image, { saveToPhotoLibrary=true, isFullResolution=true } )
-- cleanup
capture:removeSelf()
capture = nil
image:removeSelf()
image = nil
Related
I have a photo/gif app I made previously using AVFoundation as a base for the camera and taking photos, but I wanted to upgrade it to add some live filtering and post capture filtering too.
After some digging I found gpuimage/gpuimage2 and since my project is in swift 3 I started replacing my previous camera module with gpuimage.
I got the camera to work again but I have issues capturing a photo from the camera to store it as a uiimage until it is uploaded to a server.
do {
self.videoCamera = try Camera(sessionPreset: AVCaptureSessionPresetPhoto, location: .frontFacing)
} catch {
self.videoCamera = nil
print("Couldn't initialize camera with error: \(error)")
}
this is my init and then this is where I place the camera feed in the view
self.filterView!.frame = self.view.frame
self.filterView!.orientation = .portraitUpsideDown
self.filterView!.fillMode = .preserveAspectRatioAndFill
self.videoCamera! --> self.filterView!
self.videoCamera!.startCapture()
as you can see for the moment I don't want to use any filters, I'm trying to first get the basic functionality back (i.e. showing a camera feed the taking 1-5 images in a row)
I noticed there was a saveNextFrameToURL but it saves the file on the device but I only want the uiimage so this is what I put to replace the content of my takePhoto method (images is nil on first run)
func takePhoto(){
if self.images == nil {
self.images = []
}
let pictureOutput = PictureOutput()
pictureOutput.encodedImageFormat = .jpeg
pictureOutput.imageAvailableCallback = {image in
self.images!.append(image)
}
self.videoCamera! --> pictureOutput
}
My issue is that imageAvailableCallback is simply never called (I tried placing a breakpoint in it but nothing) whereas it goes through the rest of the method not raising any errors or warning.
what am I doing wrong ? is it even possible to capture a still image from a non filtered view ? if so how can I add a filter that would not change the image as such so I can still do some unedited photo capture in my app?
I've been going at it for over 2 weeks now and every time I search if anyone had the same issue I only find issues about editing a still image or a filtered image and when I tried filtering the image as such:
self.filterView!.frame = self.view.frame
self.filterView!.orientation = .portraitUpsideDown
self.filterView!.fillMode = .preserveAspectRatioAndFill
self.baseFilter = BrightnessAdjustment()
self.videoCamera! --> self.baseFilter --> self.filterView!
self.videoCamera!.startCapture()
and the takePhoto method
func takePhoto(){
if self.images == nil {
self.images = []
}
let pictureOutput = PictureOutput()
pictureOutput.encodedImageFormat = .jpeg
pictureOutput.imageAvailableCallback = {image in
self.images!.append(image)
}
self.baseFilter! --> pictureOutput
}
I get a white screen instead of my camera feed and still no image.
Any help would be appreciated thank you
I found where my problem was by looking at similar issues and the comments (found one where Brad Larson commented here
Basically it has to do with the lifespan of my pictureOutput variable, since it was enclosed inside a method is didn't last long enough for the callback to be made and to save the image, by making my pictureOutput variable a class variable I solved my issues
I am developing a chat app using parse. I want to play the vodeo when users click on the video message and Display expandable image when the user click on the picture message. for that I need to differentiate image and video. Kindly guide me to do that...
Surely the easiest way will be of course to look at the file extension...?
For future googlers ... on didTapMessageBubbleAtIndexPath delegate you should check for item class
let message = yourMessageArray[indexPath.item]
if message.isMediaMessage() {
if message.media().isKindOfClass(JSQPhotoMediaItem) {
//Handle image
} else if message.media().isKindOfClass(JSQVideoMediaItem) {
let video = message.media() as! JSQVideoMediaItem
let videoURL = video.fileURL
}
}
Save this information in another field on Parse during the asset upload.
Hey so I'm trying to have a button that when pressed allows the user to choose 2-5 pictures from their photo library then have whatever photo chosen be set onto a uiimageview? I was looking online and couldn't find anything related to how to do it in swift?
Thanks
I worked out using this : https://github.com/zhangao0086/DKImagePickerController .
Getting selected image's thumbnail images:
let pickerController = DKImagePickerController()
pickerController.sourceType = .Photo
pickerController.didCancelled = { () in
println("didCancelled")
}
pickerController.didSelectedAssets = { [unowned self] (assets: [DKAsset]) in
println("didSelectedAssets")
println(assets)
for(var i = 0; i<(assets.count); i++){
print(assets[i].url)
self.PickedArray .addObject(assets[i].thumbnailImage!)
}
self.performSegueWithIdentifier("SegueToPhotoLibraryView", sender: self)
Getting selected image's urls :
assets[i].url instead of assets[i].thumbnailImage
Hope it helps!
Currently iOS does not provide an image picker out of the box that lets you pick multiple images from the photo library. UIImagePickerController only lets you select one image.
But there are several image picker implementations available that let you pick multiple images. You can find a whole bunch at cocoacontrols.com as #ytbryan already mentioned.
I am currently not aware of any multiple image picker implemented in Swift. If someone finds one, please edit and post the link.
Titanium / for an iOS App:
How can I manage to take a photo, and then use this one later in a new function to for example show the photo, and put a slightly larger duplicate of it with a transparency on top of itself?
Note that I tried to edit the answer from Mitul Bhalia with the following, but the edit got knocked back. So here's how you do it:
After taking the image, you can store it as a variable in the global object, Alloy.Globals. You can then access this else where or later on in your app.
For example:
takePhotoButton.addEventListener('click', function(){
Titanium.Media.showCamera({
success:function(event) {
if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
// Store the file in a variable
var image = event.media;
// Store the image in the global object
Alloy.Globals.temporaryImage = image;
} else {
alert("got the wrong type back ="+event.mediaType);
}
},
...
And somewhere else in your app, after the image has been stored, for example:
var anImage = Ti.UI.createImageView({ image: Alloy.Globals.temporaryImage })
Also note that extensive use of the global object can cause memory issues, so try not to overdo it.
If you want to save photo then you can use Alloy.Globals to save data globally so you can use it later.
Alloy.Globals.photo = blob object;
Here is how I am currently solving my problem:
takePhotoButton.addEventListener('click', function(){
Titanium.Media.showCamera({
success:function(event) {
if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
// Store the file in a variable
var image = event.media;
var filename = 'myPhoto.jpg';
takenPhoto = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
takenPhoto.write(image);
} else {
alert("got the wrong type back ="+event.mediaType);
}
},
...
and then later I can use takenPhoto to show the picture I have taken with the camera.
But I do not really know if this is the best way and if it is even correct, as I do not use 'var' to initiate takenPhoto. But if I use 'var' I cannot use takenPhoto outside of the function.
I am developing a phoneGap application in IOS where I use getPhoto('Camera.PictureSourceType.PHOTOLIBRARY');
to access the photo library and select an image. following is the onPhotoURISuccess method where I need to get the url of the image and pass it to my native plugin to validate it's filesize, resolution and file extension.
this is my getPhoto() method
// A button will call this function
function getPhoto(source)
{
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100,
destinationType: navigator.camera.DestinationType.NATIVE_URI, sourceType: source });
}
and this is the onPhotoURISuccess method,
// Called when a photo is successfully retrieved
function onPhotoURISuccess(imageURI)
{
img_uri = imageURI;
console.log('NATIVE_URI==>'+img_uri);
// Get image handle
var imgPrev = document.getElementById('imgPreview');
// Unhide image elements
imgPrev.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
imgPrev.src = imageURI;
}
I have three options for this according to the phoneGap documentation. using DATA_URL, FILE_URI or NATIVE_URI.
FILE_URI seems to be hiding underlying data of the image where it always returns me a jpeg image thus the actual extension is hidden
assets-library://asset/asset.JPG?id=5CF16D20-9A80-483A-AC1C-9692123610B1&ext=JPG
I want to know how to get the actual image name along with the extension from this.
I need to get the image name and validate the extension.
someone please do help me with posssible approach for me to follow
thanks in advance
If you could get an url to asset, which is
assets-library://asset/asset.JPG?id=5CF16D20-9A80-483A-AC1C-9692123610B1&ext=JPG
You can get real name of file, by this asset:
NSString* originalFileName = [[yourALAsset defaultRepresentation] filename];