How to Crop image to the maximum image rect? - cocoa

In Mac OSX,
I have an image with black pixel in all 4 directions.
I want to programmatically crop the image to the maximum image rect.
Should i check for the black pixel and then create the crop rect or is there any supported API is there?

Create an NSImage of the desired size, lock focus on it, draw the desired crop rectangle of the source image into the whole bounds of the destination image, and unlock focus. The image you created now contains the crop from the source image.
Note that this will lose information like resolution (DPI), color profile, and EXIF tags. If you want to preserve those things (probably a good idea), use CGImage:
Use CGImageSource to load the image. Be sure to recover the properties of each image from the file, as well as the images themselves. And note that I used the plural: TIFF files can contain multiple images.
Use the CGImageCreateWithImageInRect function to crop out the desired section of each image. Don't forget to release each original image as appropriate.
If you want to write the cropped-out images to a file, do so using CGImageDestination. Pass both the images and the attributes dictionaries you obtained in step 1.

Related

Recognize an BitmapImage

From a starting image loaded from a path, I crop the image itself. I assign the images obtained from the Crop to the Image controls XAML by clicking on them with the mouse: aas if I were taking the pieces of a puzzle and wanting to reassemble the image.
I can't find a way to recognize individual images to be able to verify that the sorting is correct.

Flutter use InteractiveViewer to crop an image

I'd like to use InteractiveViewer in order to implement my own image crop.
Steps:
The user pans and scales an image, using InteractiveViewer
The user clicks a button
Get the "viewable" part of the InteractiveViewer content (bounding box)
Using this library, crop the image
Resize the cropped image (scale down), maybe compress it, and upload to my server
I fail to understand step 3: getting the "viewable" part of the InteractiveViewer content

nothing happens when I attempt to textout to a transparent image

I am using Lazarus.
I have put 2 images on a form and synchronized their positions and sizes.
I can textout to both images, and after I made the ontop image transparent I can see the combined content of both images.
I can add further text to the bottom image and see it, but I can't see text I try to add to the transparent image.
I used the following code to make the top image transparent
image2.picture.Bitmap.TransparentColor:=clWhite;
image2.transparent:=true;
I guess I need to play with the image bitmap, but I can't find a solution that is not using other software.
Can someone help me with this please?

Powerpoint change picture without changing cropping area

I´ve a cropped picture in a powerpoint layer and I want to change the picture without changing the size of the cropping area.
If I change the image by clicking "change picture" the cropping area resizes too, to show the whole picture.
How can I do that without changing the cropping area?
In Apple Keynote you only have to drag the picture you want to the cropping area and you only have to align it.
From my experience, I'm afraid you have to set the crop manually by "Format Picture" -"Crop" to remain the same cropping area when you replace a picture.
This isn't much help, but Libreoffice will do this. Crop, resize, then select your image and re-insert a new image - formatting will be the same, perfect for when you want to quickly redo formatting for same sized images.
In my experience, a picture that you insert to replace an existing one, using Change Picture, will "inherit" the crop&size settings of the old picture IF the old&new images are actually of the same size (in pixels) - if not, the new one will revert to the default crop&size so you will have to redo these manually.
This changes if the image to-be-replaced has any crop setting applied to it in Powerpoint. In this case, the replacing image will not inherit those, and might also be inserted with a different size&position, leading most likely to an unwanted result & further work needed.
A workaround I found is to first remove the crop setting from the old picture, replace with new image, then reapply the crop. This is still less work than having to manually redo the size&position (or to define these based on numbers copied from the PropertiesPane of the old image).
Quick work around: if you plan to have multiple same size images and you wish to use change image to swap the content on each page (something we do with floor plans all the time); don't bother cropping them.
Put the whole image in and crop it by sticking shapes on top of it, which are the same color as the presentation background color, like a mask.
optionally crop the images only when the whole presentation is finished.

java & SWT - how to use masking on images

i'm trying to use masking on an image in order to set a part of the image to be transparent.
from what i've read , it's supported by the SWT library , but i can't find a way to do it . i can't find even an example for that .
i've therefore created my own way to do it , by implementing the masking part :
first i find an RGB value that isn't taken anywhere on the image , and then i set it to be the transparency color. then i take the masking image , and use it to put the correct pixel (either transparent or taken from the source image) in order to create a new image.
it works , but i wish i had a simpler method .
can anyone please help?
This constructor on the Image class looks to do the job:
public Image(Device device,
ImageData source,
ImageData mask)
from the javadoc...
Constructs an instance of this class, whose type is SWT.ICON, from the two given ImageData objects. The two images must be the same size. Pixel transparency in either image will be ignored.
The mask image should contain white wherever the icon is to be visible, and black wherever the icon is to be transparent. In addition, the source image should contain black wherever the icon is to be transparent.
Parameters:
device - the device on which to create the icon
source - the color data for the icon
mask - the mask data for the icon

Resources