Skip to content
Browse files

new example app to show and test different scaling and compressing

  • Loading branch information...
1 parent 85358bd commit ed7f1aea59c625bd8bc24d2d498e238aa24cea78 @sideshowcoder committed Aug 22, 2011
View
BIN example/144K.JPG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN example/1500K.JPG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN example/191K.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN example/324K.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
79 example/app.js
@@ -6,62 +6,53 @@
// open a single window
var window = Ti.UI.createWindow({
- backgroundColor:'white'
+ backgroundColor:'black'
});
-var f = Ti.Filesystem.getFile('test.jpg');
-var img = f.read.blob;
-var cImgView = Ti.UI.createImageView({
- top: 100,
- width: 50,
- left: 20
+// Load images
+var images = []
+var f144 = Ti.Filesystem.getFile('144K.JPG');
+images.push(f144.read.blob);
+var f1500 = Ti.Filesystem.getFile('1500K.JPG');
+images.push(f1500.read.blob);
+var f191 = Ti.Filesystem.getFile('191K.JPG');
+images.push(f191.read.blob);
+var f324 = Ti.Filesystem.getFile('324K.JPG');
+images.push(f324.read.blob);
+
+var iv = Ti.UI.createImageView({
+ top: 30,
+ left: 0
});
-var c2ImgView = Ti.UI.createImageView({
- top: 200,
- width: 50,
- left: 20
+var btn = Ti.UI.createButton({
+ top: 0,
+ height: 30,
+ title: 'Press to Switch Images',
+ left: 0
});
-var sImgView = Ti.UI.createImageView({
- top: 300,
- width: 100,
- left: 20
-});
-
-window.add(cImgView);
-window.add(c2ImgView);
-window.add(sImgView);
+window.add(iv);
+window.add(btn);
window.open();
// Init module
var jpgcompressor = require('com.sideshowcoder.jpgcompressor');
Ti.API.info('module is => ' + jpgcompressor);
-// Test
-
-// Set and read compress Factor
-Ti.API.info('Set compress Size to 1000...');
-jpgcompressor.setCompressSize(1000);
-Ti.API.info('Compress Size: ' + jpgcompressor.compressSize);
-Ti.API.info('Unset worst quality: ' + jpgcompressor.worstCompressQuality);
-
-// Compress an image
-var cImg = jpgcompressor.compress(img);
-jpgcompressor.setCompressSize(100);
-Ti.API.info('Set compress Size to 100...');
-jpgcompressor.setWorstCompressQuality(0.2);
-Ti.API.info('Compress Size: ' + jpgcompressor.compressSize);
-Ti.API.info('Unset worst quality: ' + jpgcompressor.worstCompressQuality);
-var c2Img = jpgcompressor.compress(img);
-cImgView.setImage(cImg);
-c2ImgView.setImage(c2Img);
-
-// Scale image
-Ti.API.info('Image width: ' + img.width + ' heigth: ' + img.height );
-var sImg = jpgcompressor.scale(img, 100, 100);
-Ti.API.info('Scaled image width: ' + sImg.width + ' heigth: ' + sImg.height );
-sImgView.setImage(sImg);
+// Set and read compress Factor to 100Kb
+jpgcompressor.setCompressSize(102400);
+jpgcompressor.setWorstCompressQuality(0.65);
+
+var curr = 0;
+var names = ['144K', '1500K', '191K', '324K'];
+
+btn.addEventListener('click', function(){
+ Ti.API.log(names[curr]);
+ cImage = jpgcompressor.scale(images[curr], 960, 960);
+ iv.setImage(jpgcompressor.compress(cImage));
+ curr = (curr + 1) % 4;
+});

0 comments on commit ed7f1ae

Please sign in to comment.
Something went wrong with that request. Please try again.