Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Titanium Custom Camera Module (iPhone)

$
0
0

Hey guys,

Ok so I've received a TON of help here from everyone over the years so I decided not clean it up and make this into a marketplace module or anything like that and just put it out there for anyone to use. I'll also be the first to admit that the code here is far from perfect, as I've never made an appcelerator module before (or coded anything in objective-c ha) so bare with me. I built this as I needed it for a project and will continue to improve it for use in other ones :)

I also want to throw out there that the game plan was to clean up the code and make sure all of the places that I found help (various blogs, Q&A posts, etc.) were referenced but just don't have the time this morning and I know people are looking for something like this and wanted to get it out there. So I will make sure to go through and do that tonight as well as clean up some code and fix a couple things I already see :)

The point of this module is to allow you to take a photo and have it fill up a view, without actually using the iPhone popup camera which has the shutter affect. It's used like this:

var SquareCamera = require('com.mfogg.squarecamera');
 
var cameraView = SquareCamera.createView({
    top: 60,
    height: 300,
    width: 300,
    backgroundColor: "#fff"
});
 
// Event that listens for the flash to turn on
cameraView.addEventListener("onFlashOn", function(e){
    alert("Flash Turned On");
});
 
// Event that listens for the flash to turn off
cameraView.addEventListener("onFlashOff", function(e){
    alert("Flash Turned Off");
});
 
// Event that listens for the camera to switch
cameraView.addEventListener("onSwitchCamera", function(e){
    alert("Camera Switched");
});
 
// Event that listens for a photo to be taken
cameraView.addEventListener("onTakePhoto", function(e){
    alert("Picture Taken");
});
 
// Take Photo Button
var take_photo = Ti.UI.createView({
    backgroundColor: "#fff",
    height: 80,
    width: 80,
    bottom: 10,
    borderRadius:40
});
 
take_photo.addEventListener("click", function(e){
    cameraView.takePhoto();
});
 
win.add(take_photo);
 
// Flash
 
var flash_on = false; //Flash defaults to 'Off'
 
var flash = Ti.UI.createView({
    backgroundColor: "#fff",
    height: 40,
    width: 40,
    top: 10,
    left: 10
});
 
flash.addEventListener("click", function(e){
    if(flash_on == true){
        cameraView.turnFlashOff();
        flash_on = false;
    } else {
        cameraView.turnFlashOn();
        flash_on = true;
    };
});
 
win.add(flash);
 
// Switch Camera
 
var switch_camera = Ti.UI.createView({
    backgroundColor: "#fff",
    height: 40,
    width: 40,
    top: 10,
    right: 10
});
 
switch_camera.addEventListener("click", function(e){
    cameraView.switchCamera();
});
 
win.add(switch_camera);
 
win.add(cameraView);
win.open();
Hopefully that makes sense and is self explainatory. I need to head to work so feel free to post any questions here and anyone who can, please help make this module even better!

Known issues:

1) Some build warnings that I need to take a look at (still builds successfully)

2) You can only take a picture once. I think I'm stopping the input and then trying to take a picture which obviously is making it crash... I should make it not crash :)

3) I should add a "reset" or "cancel" feature to allow you to take a second picture.

4) Clean up all of the framework stuff in there

Feel free to modify/edit/fix/improve/suggest/etc etc on Github


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>