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

image save compress module

$
0
0

Hi there

Analize this code I would like to take a picture, then validate if the picture exceeds a prescribed weight. After this if the photo has an ideal weight, gives it to the module "imagefactory" to compress.

Titanium.Media.showCamera({
 
                                 success:function(event) {
 
                                        var cropRect = event.cropRect;
                                        var image = event.media;
 
 
                                        var filename = code+ide+Ti.App.Properties.getString("iduser");
                                        var userDir = Titanium.Filesystem.applicationDataDirectory; 
 
                                        var saveFile = Titanium.Filesystem.getFile(userDir, filename);
                                        saveFile.write(image);
                                        if(saveFile.size > 700000) {
                                            alert('La imagen excede el máximo permitodo, por favor baje la resolución de su cámara!');
                                            saveFile.deleteFile();
                                            return false;
                                        }else {
                                            //saveFile.deleteFile();
                                            var myImg = ImageFactory.imageAsResized(saveFile, {width:640, height:480, quality:0.2});
 
                                            var uploadFile = Titanium.Filesystem.getFile(userDir, filename); 
                                            uploadFile.write(myImg);
                                            if (uploadFile.exists()) {
 
                                                view.backgroundColor = 'green';
                                                var now = new Date();
                                                var date = now.getFullYear() + '-' + (now.getMonth()+1) + '-' + now.getDate();
                                                var time = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
                                                var create = date+" "+time;
 
                                                var db = Ti.Database.open("elite.db","elite");
                                                db.execute('INSERT INTO IMAGES_CHECKLIST (form_id, image, created) VALUES (?,?,?)',numero,filename,create);
                                                db.close();
 
                                                scrollView.scrollToBottom();
                                            } else {
 
                                                alert('Error en captura!');
                                            }
                                        }
 
 
 
                                },
 
                                allowImageEditing:false,
                                saveToPhotoGallery:false
 
                            });
Then if you realize, I keep the name of the photo on a table, to rescue another time.

There are times when the picture shows not well, or not pull it out.

I hope I understand the question.

Android sdk 3.1


Viewing all articles
Browse latest Browse all 8068

Trending Articles



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