Fit the image to the screen in blackberry - blackberry

How can i fit a large image on a BlackBerry simulator so that the whole image appears without getting cropped?Can anyboby help me with a code example

There are many ways you could do this but if it fits with your requirements then the backgroundfactory is nice.
http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/ui/decor/BackgroundFactory.html
// specify the bitmap and xy positioning to meet your needs
Background background = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("bitmap.png"),Background.POSITION_X_LEFT, Background.POSITION_Y_BOTTOM, Background.REPEAT_NONE);
// create a field manager and set its BG to this one
VerticalFieldManager body = new VerticalFieldManager(USE_ALL_WIDTH|USE_ALL_HEIGHT);
body.setBackground(background);
add(body);
//Some other options
//Background.REPEAT_NONE
//Background.REPEAT_SCALE_TO_FIT
//Background.REPEAT_VERTICAL
//Background.REPEAT_HORIZONTAL

Related

Tiled Background Image Moving Diagonally In View

I've seen many solutions out here but they're not exactly what I'm looking for. What I'm attempting to do is have the view's background to move an image multiple times-- slowly and diagonally rather than horizontally or vertically.
From a web designing perspective, this can be achieved with a tiled bg.gif where the image gives the effect of an image moving without additional programming.
Example:
However, I'm not sure whether this is achievable within Swift programming. I'm sure alternative solutions are out there like having a single image (a smiley face) tiled to fill the view frame and have it move diagonally by incrementing it's x & y coordinates.
I'm new to iOS development and Swift yet I am learning a lot! Much help will be appreciated.
refer this two links. it will help to achieve what you want. click here and click here
Update as advised in comment : download SwiftGif and Import the Gif.swift in your project and do the following:
// Returns an animated UIImage
let myGif = UIImage.gifWithName("imggif")
// Use the UIImage in your UIImageView
let imageView = UIImageView(image: myGif)
here imggif is your gif image which shown in question. put it in your project
hope this will help :)

How can I tile the background with UIImageViews with code efficiently?

I'm working in Xcode 6 on tiling the iPhone background with many UIImageViews and I'd like to know if this is the most efficient solution.
I know one simple solution would be to create image views in the storyboard and cover the entire screen with them manually. I'd like to do it with code. Here's the code I have currently (5x5 is an okay size since I can scale it up or down to fill the screen with bigger or larger images):
CGRect tiles[5][5];
UIImage *tileImages[5][5];
UIImageView *tileViews[5][5];
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
tiles[i][j] = CGRectMake(50*i,50*j,50,50);
tileImages[i][j] = [UIImage imageNamed:#"tile.png"];
tileViews[i][j] = [[UIImageView alloc] initWithFrame:tiles[i][j]];
tileViews[i][j].image = tileImages[i][j];
[self.view addSubview:tileViews[i][j]];
}
}
Currently all the images are the same, but in the long haul I'm going to make them dependent on various factors.
I have read around and I know that UIImageViews are finicky. Is this the proper and memory efficient way to tile a background with UIImageViews? Is there a better way to do this? Can I manually go in after the tiles are initialized and change an image it's displaying and have it update in real time with just this?
tileView[1][2].image = [UIImage imageNamed:#"anotherTile.png"];
Thanks in advance, I just finished a basic 6-week course in IOS programming at my college so I still find myself trying to appease the Objective C Gods occasionally.
I guess my doubt would be why you need them to be image views. Drawing an image in a view or layer is so easy, and arranging views or layers in a grid is so easy; what are the image views for, when you are not really using or needing any of the power of image views?
I have several apps that display tiled images - one shows 99 bottles in a grid, one shows a grid of tile "pieces" that the user taps in matched pairs to dismiss them, one shows a grid of rectangular puzzle pieces that the user slides to swap them and get them into the right order, and one shows a grid of "cards" that the user taps in triplets to match them - and in none of those cases do I use image views. In one, they are CALayers; in the other cases they are custom UIView subclasses; but in no case do I use UIImageViews.
For something as simple as a grid of images, using UIImageViews seems, as you seem to imply, overkill. If the reason you have resorted to UIImageViews is that you don't know how to make a UIView or a CALayer draw its content, I'd say, stop and learn how to do that before you go any further.

How to dim/blur everything outside given rect in iOS?

I'm currently developing an iOS app that is using OCR.
Currently I'm using AVFoundation to preview the video from the camera (using Apples sample AVCam).
For a good user experience I want to lay out a rectangle in the preview layer. The image inside this rectangle will be the image parsed by the OCR engine. My problem is that I also would like to "dim" everything outside this rectangle and I'm currently out of ideas how to solve this. Does anybody know how to do this?
Edit
This is what I would like to accomplish (image taken from the app Horizon):
http://i.imgur.com/MuuJNS9.png
You can use two black images covering the top and bottom areas that you want to "dim", set the alpha of those images to a certain value, like 0.5.
Why not add a subview that covers the entire screen and set the background color to a semi transparent gray - your gray overlay?
And then add the image parsed by the OCR engine add a subview of this grayoverlay int the center of it

Bulk creation + edit images

I currently use photoshop + datasets to automatically create CTA buttons for testing on a clients website. The dataset often contains text and other changes like underline or background colour, as well as alignment and font formatting.
Typically these can run into the thousands, which photoshop handles very well but the task is technical and not graphical. For me photoshop is overkill for the task.
Is anyone aware of a solution that is more code-friendly? I am currently playing around with canvas on HTML and fabric.js. This allows me to manipulate a template image, and I hoping I can pipe in code to create a number of .png output images.
Canvas would be well suited to your automation
First, create a base .png and then programmatically alter it in thousands of ways.
Save the results to appropriately named .png files.
You could even create an on-screen viewer that dynamically creates thousands of variations. The client(s) could browse the dynamically created images and select the variations that interest them. That would eliminate the need for thousands of saved files.
Here are just a start of canvas commands you can use to automate:
Apply text:
context.font("italic 14pt Verdana");
context.textAlign = textAlign; // left|right|center
context.fillText("anyText", x,y);
Underlines are just a bit trickier:
// use measureText to get the text width
var textWidth =context.measureText(text).width;
// 1-time only, pre-calculate all the “Y” underline offsets for each font you use
var ULOffset=lookupULOffset(font,fontSize);
context.moveTo(x,y+ULOffset);
context.lineTo(textWidth,y+ULOffset);
context.stroke();
Change background color or anything else that you've created a sub-layer for!
Like Photoshop Canvas has an excellent set of compositing operations.
Source-over
Source-in
Source-out
Source-atop
Lighter
Xor
Destination-over
Destination-in
Destination-out
Destination-atop
Darker (this has been deprecated for some reason??)
You also can apply an alpha when drawing a layer as well as an alpha while drawing any canvas shapes.
In addition, check online for many image filters that have been created for canvas.
And that's just be beginning...
Happy Automating!

How to Repeat Image to Fill Background in Corona

i Got a Small Tile Image. i Want to set The Background with that image and I want to Repeat the Image to Fill the Entire background. For Example in CSS we Repeat the Background image with repeat-x and repeat-y property.
You should get the with and height of image to calculate how many times you should repeat the image.
It's not difficult but luckily there is already a module on Code Exchange.
You can use that and modify it for your needs if required.
http://developer.coronalabs.com/code/tilebg-tile-and-manage-image-display-background
See Code Exchange for more libraries: http://developer.coronalabs.com/code/

Resources