Create a thumbnail of a picture
Hi
I created an iPhone app, where you can take pictures and put it on a map. I just want a pin. When you click on it, there should be a thumbnail picture.
Is there a way to shrink the picture with Titanium Mobile?
Thanks!
Felix
5 Answers
-
There is an undocumented function called imageAsThumbnail which you should check out. It scales and crops an image blob into a square thumbnail. To use it, convert an imageView to a blob. The function takes one parameter, which is the size of the square thumbnail you want to use.
As far as using an image in the map annotation, I think you can only put the annotation in the left corner using the
leftView
property.// Convert your imageView into a blob var blob = imageView.toImage(); // Turn blob into a square thumbnail blob = blob.imageAsThumbnail(64); // Create new imageView for thumbnail var thumbnailImageView = Ti.UI.createImageView({ image: blob }); // Add image to annotation Ti.Map.createAnnotation({ leftView: thumbnailImageView });
Cheers
-Brandon
-
This is a function I slapped together to resize an image. It returns an image that is the size you specified when you call the function.
function resize_image(imagePath, height, width) { height = height || 64; width = width || 64; var imageView = Ti.UI.createImageView({ image: imagePath, width: width, height: height }); return imageView.toImage(); }
-
imageAsThumbnail() works well, but has anybody notice that it adds a white bolder around the thumbnail? For example, if I do imageAsThumbnail(192), the resulting thumbnail is 194x194 and there is a one pixel white bolder around the image
-
There is a 1 pixel boarder by default - see the documentation for imageAsThumbnail:
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Blob.imageAsThumbnail-method.html
You should be able to set the borderSize to 0 to remove the border.
-
can image thumnail be changed to any size you want. i think so .