I have two images one on the above and i want to erase a small part from the top image to show the background image. Is it possible transparent erase using titanium for iOS?
Thanks and regards,
GANESH M
You can do this using the ti.paint module. Specifically, its ability to have an image on the canvas which can be erased. After installing, try this:
// Container window
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
// Background image
var backgroundImage = Ti.UI.createImageView({
image : 'yourbgimage.png'
width : Ti.UI.FILL,
height : Ti.UI.FILL
});
// Require paint module and add to view with an erasable image
var Paint = require('ti.paint');
var paintView = Paint.createPaintView({
image : 'yourfgimage.png', // This is the image you erase
eraseMode : true,
width : Ti.UI.FILL,
height : Ti.UI.FILL,
strokeColor : '#0f0', strokeAlpha : 255, strokeWidth : 10
});
win.add(backgroundImage);
win.add(paintView);
win.open();
Related
I have added some images in two different views & placed them inside a ScrollableView. On click of images, EventListener is not getting executed. This code works perfectly for Android(appcelerator) but for IOS it's not working.
Scroll & other Events are working fine. The problem seems with items placed in ScrollableView.
var dataView = Ti.UI.createView({
layout : 'horizontal',
top : '0'
});
var textHolderView = Ti.UI.createView({
layout : 'vertical',
width : '50%'
});
var iconView = Ti.UI.createView({
layout : 'horizontal',
width : '24.5%'
});
var header = Ti.UI.createLabel({
text : "Some Text",
font : {
fontSize : '12dp',
fontFamily : 'OpenSans-Semibold',
fontWeight : 'normal'
},
height : '38dp',
left : '15%',
color : '#000',
width : '85%',
touchEnabled : false
});
var image1 = Ti.UI.createImageView({
image : "/images/individual.png",
height : '18dp',
left : '5dp',
width : '13%',
top : '25%'
});
var slideOptionsView = Ti.UI.createView({
backgroundColor : "#1268b3",
layout : "horizontal"
});
var img_activity = Ti.UI.createImageView({
image : "/images/activity_temp.png",
height : "30dp",
width : "70dp",
left : "10%",
top : "15dp",
touchEnabled : true
});
textHolderView.add(header);
iconView.add(image1);
dataView.add(textHolderView);
dataView.add(iconView);
slideOptionsView.add(img_activity);
var scroll = Ti.UI.createScrollableView({
views : [dataView, slideOptionsView],
showPagingControl : false,
});
// Event Listeners on click for above images
img_activity.addEventListener('click', function(e) {
alert("img_activity");
});
image1.addEventListener('click', function(e) {
alert("image1");
});
$.someView.add(scroll);
$.index.open();
Thanks.
I have 10 image views stacked on one another. (for loop)
9 of them are set to visible = false.
1 of them is set to visible = true.
I was wondering if there is a way to only load the image when the imageview visibility is set to true. i.e. after an image view is removed off the stack.
The trouble I am having is that it is loading all the images at the same time in the stack, slowing everything down.
for (var i = 0; i < peopleJson.users.length; i++) {
//create containers to store every child object
containers[i] = Titanium.UI.createView({
id : 'container',
visible : false,
width : '100%',
zIndex : '0',
});
imageSwipeView[i] = Titanium.UI.createImageView({
image : peopleJson.users[i].pictures[0],
visible : true,
containerObj : containers[i],
containerObjPrev : containers[temp],
pictures : peopleJson.users[i].pictures,
indImageView : indImageView[i],
basket : LabelBasket[temp],
top : 0,
zIndex : 2,
width : '100%',
defaultImage : 'images/plainbg.png',
height : 510,
});
containers[i].add(imageSwipeView[i]);
win.add(containers[i]);
if (i == (peopleJson.users.length - 1)) {
//show last container when for loop is executed
containers[i].visible = true;
$.view_indicator.visible = false;
}
[..]
This code snippet basically says stack up the containers ontop of one another, once loop has executed show last container.
Later on I have an onclick event for each image view, if clicked, it removes the container at the top of the stack and makes the one underneath visible.
What I am trying to do , is only LOAD up the imageView remote images when the container becomes visible. Right now, it will try and load the images visible or not visible.
You can try setting path to image to different property:
imageSwipeView[i] = Titanium.UI.createImageView({
_image : peopleJson.users[i].pictures[0],
...
})
and when you are setting up visible = true update image property:
containers[i].visible = true;
if (!imageSwipeView[i].image) {
imageSwipeView[i].image = imageSwipeView[i]._image;
}
$.view_indicator.visible = false;
The following code is working for the most part, however sometimes after being changed into a blob, the image view does not display the image.
//store in temp image view, convert to blob
imageViewTemp.image = "imagename.jpg"
blob = imageViewTemp.toBlob();
albumTitle = data[x].name + ' (' + numberPhotos + ')';
var row = Titanium.UI.createTableViewRow({
titleAlb : data[x].name,
width : '100%',
height : 'auto'
});
var image = Titanium.UI.createImageView({
top : 0,
left : 0,
width : '75',
height : '75'
});
var title = Titanium.UI.createLabel({
text : albumTitle,
top : 0,
left : 110,
width : 'auto',
height : 'auto'
});
var width = blob.width;
var height = blob.height;
//crop so it fits in image view
if (width > height) {
image.image = ImageFactory.imageAsCropped(blob, {
width : height,
height : height,
x : 60,
y : 0
});
} else {
image.image = ImageFactory.imageAsCropped(blob, {
width : (width - 1),
height : (width - 1),
x : 60,
y : 0
});
}
row.add(image);
row.add(title);
rows.push(row);
}
In order to change the dimension of the image, I am using a module called image factory. Before I can change it, I have to store the image inside a tempory image view which I then convert into a blob:
blob = imageViewTemp.toBlob();
The problem is after the screen is rendered sometimes this will not work:
image.image = ImageFactory.imageAsCropped(blob, {
width : height,
height : height,
x : 60,
y : 0
});
Othertimes it will.
I have read online that the problem might be linked to the post layout cycle, but I am not sure, or how to proceed
http://developer.appcelerator.com/question/174329/what-are-the-difference-between-toblob--toimage
All help appreciated.
Solved the problem.
You have to download the image first using a REST API method (GET) before placing it into the temporary image view, otherwise the temp image view will be rendered before the file has been fully downloaded (.toImage is an async call back method), making way for a useless blob and no image.
The only problem with this method, is that you are reliant on your REST API calls to not fail.
I am trying to display a remote image url into webview in both iPhone & Android using Appcelerator Titanium. The remote image is displayed in webview but the full image doesn't fit into the webview in app.
Code:
var webView = Ti.UI.createWebView({
url : 'https://cloudinary-a.akamaihd.net/dhl5ctlq1/image/upload/v1364796700/business_logo_4_53_1364308382.jpg',
top : 0,
left : x(60),
height : '80dp',
width : '80dp',
scalesPageToFit : true,
showScrollbars : false,
scrollsToTop:false,
backgroundColor : "red"
});
Dont use a WebView, a WebView is for displaying web content (read: HTML), instead just use a ImageView, these support remote URL's, just remember that on iOS these remote images are cached, but on Android they are NOT (big oversight on appcelerator's side). Try this instead:
var image = Ti.UI.createImageView({
image : 'https://cloudinary-a.akamaihd.net/dhl5ctlq1/image/upload/v1364796700/business_logo_4_53_1364308382.jpg',
top : 0,
left : x(60),
height : '80dp',
width : '80dp'
backgroundColor : "red"
});
I have some images that are .png's with transparent backgrounds however, when they are added to the stage they have white backgrounds. Am i missing a trick here?
Each image is added like so:
var layer = new Kinetic.Layer();
var book = new Image();
book.onload=function () {
bookImg = new Kinetic.Image ({ x: 885, y: 780, offset: [85.5, 106], image:book, name:book, opacity: 0, /*scale:{x:0.5, y:0.5}*/ });
layer.add(bookImg);
stage.add(layer);
}
book.src = "images/book.png";
is it that the layer itself is what's creating the white background?
a little confused!
Cant it be that you have to set the background to transparent? Not only the picture itself but the image-object containing the image. Maybe the layer aswell.
You shouldn't need to set the opacity on a Kinetic.Image() object. If you want it to be invisible, either initially or after being placed, simply use hide() (and subsequently show() to re-show it). Or set visible to false in the parameters. The minimum needed to place an image on the stage looks like this:
var image = new Kinetic.Image({
x: 0,
y: 0,
image: imageObj,
width: 300,
height: 120
});
layer.add(image);
layer.draw();
This assumes your layer has already been added to a Kinetic.Stage() and the image has loaded ( imageObj.onload = function(){} ). Including a name is fine, the offset and opacity (and even scale) are valid key/value pairs for parameters but not really necessary when creating the image. These can always be set after the image has been added to the layer as well (using one of the many setters in the KineticJS library).
I'd try using a minimalist approach to see if the image shows up as intended first, then go from there.