I want to add image and some text on another image and create a single image. I have got to add text but not able to figure out that how to add image. Any help?
This snippet assumes you have UIImage's named bottomImage for the base image to be drawn upon, and topImage that will be drawn ON (above) the bottomImage. xpos,ypos are floats to describe the target x,y (top left) position where topImage will be drawn, and targetSize the size in which topImage will be drawn on bottomImage.
...
UIGraphicsBeginImageContext( bottomImage.size );//create a new image context to draw offscreen
[bottomImage drawInRect:CGRectMake(0,0,bottomImage.size.width,bottomImage.size.height)];//draw bottom image first, at original size
[topImage drawInRect:CGRectMake(xpos,ypos,targetSize.width,targetSize.height) blendMode:kCGBlendModeNormal alpha:1];//draw the image to be overlayed second, at wanted location and size
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();//get newly drawn image context into a UIImage
UIGraphicsEndImageContext();//stop drawing to the context
return newImage;//return/use the newly created image
This is not thread safe - creating a UIImage in a thread is not recommended.
Related
I need a functionality where i need to be able to position image properly inside the frame of the image itself.
As you can see in the image, the image container will be of a fixed size, and if the image is bigger than the frame itself, I need to be able to reposition image inside the frame. I tried clipping the image with a rectangle and positioning the image inside the rectangle but the clip creates a new image equal to the size of the rectangle so it has not worked so far. Is there any property in the fabric.Image class that lets us move image position inside?
Since Fabric.js v2, image cropping can be done using a combination of four properties: width, height, cropX, and cropY. (http://fabricjs.com/v2-breaking-changes#image)
As an example, an image with native dimensions of 500x500 pixels can be center cropped to 300x300 pixels like this:
img.set({
width: 300,
height: 300,
cropX: 100,
cropY: 100
});
I am using keras-retinanet model to detect an object from an image. Problem I am facing with this is if image is not orientated correct then model is unable to detect the object. For example if image is like this:
If I manually flip this image by 180 then model is able to detect the object.
I am doing following image processing before sending to model-
def _preprocess_image(self, image):
draw = image.copy()
draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)
image = preprocess_image(image)
image, scale = resize_image(image)
return draw, image, scale
In above method how can I add a check if orientation is not correct and then can correct it?
You should retrain the network with data augmentation containing all the orientations.
I don't think it is possible to determine that the image is in the original position or flip by 180°.
Unless if the origin (0,0) top left position is recorded in the meta data of the image and you have/find access to the metadata of the image itself (very unlikely possibility imo).
I'm having a bit of a problem: I'm trying to access the width of a container in which I've added a sprite to, but it seems to return as 1. However, when I inspect the object in the console, it gives me the proper width.
I wrote up a code pen showing the issue, but it goes something like this:
var container = new PIXI.Container();
app.stage.addChild(container);
var sprite = PIXI.Sprite.fromImage('https://i2.wp.com/techshard.com/wp-
content/uploads/2017/05/pay-1036469_1920.jpg?ssl=1&w=200');
container.addChild(sprite);
console.log(container.height);
console.log(container);
The first console log returns 1, while if I go into the object in the second log it gives me 141.
I'm trying to center the container like in the demo. The demo container returns the proper width, unless you try and do it for only one "bunny" (replacing bunny texture with internet image, also the for loop is commented out).
Any suggestions on a proper approach for this?
Cheers
There's a few things to address here.
Firstly, what the problem in your codepen is:
You're creating a texture from an image that has yet to be loaded.
Until the image loads pixi will not be able to give you the dimensions of it, and the container reports a width and height of 1 when you immediately query them. If you put the same console.log statement in a timeout then it will report the dimensions after the image has loaded and thus the dimensions will be accurate.
Logging out the object itself seems to work because when you examine the contents of it they've been updated to the correct values because the image has loaded by that point.
If the texture is already in the cache at the point that you create a new sprite using it then you won't have to wait before you can access its true dimensions.
Secondly, why the bunny example on pixi's site doesn't have the same problem:
Actually, it does. You just don't notice it.
The magic is in the bunny.anchor.set(0.5);. It lines 25 sprites with width and height of 1 out in a grid. By spacing them out, their container now has width and height of 160.
This container is now centered immediately based on its current dimensions, and then when the sprite textures finish loading and the sprites are updated with their new dimensions. Due to their anchor being set to 0.5, however, this means they remain centered despite their container now being larger.
You can play around with using a larger image than the bunny to exaggerate things and changing the anchor value, along with using the rerun code button rather than just refreshing the page. If you rerun the code the image being used for the texture remains cached by pixi so you get different results.
Lastly, how you would resolve this issue:
Loading your assets before creating sprites with them.
(Or at least waiting before they're loaded before querying their dimensions to position things)
You can find an example of the resource loader that pixi has here: http://pixijs.io/examples/?v=next-interaction#/basics/spritesheet.js
I'm having an issue with canvases. I have modified the Canvas.hs example program to draw an image onto the canvas with
canvas # drawImg
right after the canvas setup code; here it is for reference:
canvas <- UI.canvas
# set UI.height canvasSize
# set UI.width canvasSize
# set style [("border", "solid black 1px"), ("background", "#eee")]
where drawImg is
drawImg :: UI.Canvas -> UI ()
drawImg canvas = do
url <- UI.loadFile "image/png" "resources/img.png"
img <- UI.img # set UI.src url
UI.drawImage img (0,0) canvas
which should be the same behavior as the on click function for drawing an image in the original version of the code.
The actual behavior of this code is a blank canvas, just as in the original example before clicking on the draw image button. I would think that it should draw the image on loading. Why is this? Should I instead add this call to the line that sets up the canvas?
Is the canvas part of the DOM? Don't forget to add it to the document body with via getBody #+ [...] or thelike.
There may be another problem, though: Browsers usually load image URLs asynchronously. In fact, I'm not sure if they load image URLs at all if the image is not part of the DOM, as in your example. In both scenarios, if you try to draw an image to a canvas before its URL has been loaded, nothing will be drawn. (The easiest way to check whether this problem is the relevant one in your code is to draw polygons instead of an image.)
I want to merge two images in blackberry. one image is a big image and other image is a small one. position of small image will be define by developer. what are the possible ways?
You can use the Graphics class to draw multiple Bitmaps onto it in different offsets. Look into the Graphic.drawBitmap function. We use something like:
graphics.drawBitmap(x1, y1, icon.getWidth(), icon.getHeight(), icon, 0, 0);
Where the graphics object is the one passed by the paint method we override and icon is the large image. Than determine the x y position for the smaller image and use the same method on the graphics object:
graphics.drawBitmap(x2, y2, mark.getWidth(), mark.getHeight(), mark, 0, 0);
Where mark is the smaller image.
Hope this helps :)