Difference between CGAffineTransform on CIIMage and UIImageView
I have been playing around with CGAffineTransform
and noticed that transforming an image from the UIImageView
has a different effect then transforming it directly through the CIImage
. Here is the code:
let totalTransformationAndRotation = CGAffineTransform(rotationAngle: x)
// How I transform using the imageview
self.keyImage.transform = totalTransformationAndRotation
// How I transform using the image
var coreImage:CIImage? = myImage!.ciImage
if coreImage == nil {
coreImage = CIImage(cgImage: myImage!.cgImage!)
}
coreImage = coreImage?.transformed(by: totalTransformationAndRotation)
When used separately these two transformations come out totally differently. I understand that the unit is different for the CIImage
's transformation's dx and dy and UIImageView
's transformation's dx and dy, but even rotations have a different result. It appears to me that when rotated in the CIImage
. The rotation is centered around the bottom left, while in the UIImageView
it is centered around the center of the image.
Is it possible to rotate, scale and translate a UIImage/CIImage and have the same effect as if you applied the same transformations on a UIImageView?
Edit:
I am trying to transform a UIImage
by rotating, scaling, and translating. I have gotten the desired effect by applying a transforming on the UIImageView
's transform property but realized that I need to do the transformation directly in the image.
swift uiimageview core-image cgaffinetransform ciimage
|
show 4 more comments
I have been playing around with CGAffineTransform
and noticed that transforming an image from the UIImageView
has a different effect then transforming it directly through the CIImage
. Here is the code:
let totalTransformationAndRotation = CGAffineTransform(rotationAngle: x)
// How I transform using the imageview
self.keyImage.transform = totalTransformationAndRotation
// How I transform using the image
var coreImage:CIImage? = myImage!.ciImage
if coreImage == nil {
coreImage = CIImage(cgImage: myImage!.cgImage!)
}
coreImage = coreImage?.transformed(by: totalTransformationAndRotation)
When used separately these two transformations come out totally differently. I understand that the unit is different for the CIImage
's transformation's dx and dy and UIImageView
's transformation's dx and dy, but even rotations have a different result. It appears to me that when rotated in the CIImage
. The rotation is centered around the bottom left, while in the UIImageView
it is centered around the center of the image.
Is it possible to rotate, scale and translate a UIImage/CIImage and have the same effect as if you applied the same transformations on a UIImageView?
Edit:
I am trying to transform a UIImage
by rotating, scaling, and translating. I have gotten the desired effect by applying a transforming on the UIImageView
's transform property but realized that I need to do the transformation directly in the image.
swift uiimageview core-image cgaffinetransform ciimage
There is no such thing as a UIImage transform. Your example involves CIImage, a very different thing. If you want help doing an image transformation please state clearly what the exact goal is. If you are just trying to draw the image rotated, I wouldn’t do it any of the ways you’ve shown so far.
– matt
Nov 25 '18 at 19:21
Thanks, @matt I fixed it.
– joshLor
Nov 25 '18 at 19:36
Ok but the CIImage is still not how I would do it. I would just redraw the image into an image graphics context with a transformed CTM. Again, I could demonstrate if you would be specific.
– matt
Nov 25 '18 at 19:43
Or see my discussion at apeth.com/iOSBook/ch15.html#_graphics_context_transforms
– matt
Nov 25 '18 at 19:49
@matt which one is faster? I may have to do hundreds of the transformations concurrently
– joshLor
Nov 25 '18 at 20:05
|
show 4 more comments
I have been playing around with CGAffineTransform
and noticed that transforming an image from the UIImageView
has a different effect then transforming it directly through the CIImage
. Here is the code:
let totalTransformationAndRotation = CGAffineTransform(rotationAngle: x)
// How I transform using the imageview
self.keyImage.transform = totalTransformationAndRotation
// How I transform using the image
var coreImage:CIImage? = myImage!.ciImage
if coreImage == nil {
coreImage = CIImage(cgImage: myImage!.cgImage!)
}
coreImage = coreImage?.transformed(by: totalTransformationAndRotation)
When used separately these two transformations come out totally differently. I understand that the unit is different for the CIImage
's transformation's dx and dy and UIImageView
's transformation's dx and dy, but even rotations have a different result. It appears to me that when rotated in the CIImage
. The rotation is centered around the bottom left, while in the UIImageView
it is centered around the center of the image.
Is it possible to rotate, scale and translate a UIImage/CIImage and have the same effect as if you applied the same transformations on a UIImageView?
Edit:
I am trying to transform a UIImage
by rotating, scaling, and translating. I have gotten the desired effect by applying a transforming on the UIImageView
's transform property but realized that I need to do the transformation directly in the image.
swift uiimageview core-image cgaffinetransform ciimage
I have been playing around with CGAffineTransform
and noticed that transforming an image from the UIImageView
has a different effect then transforming it directly through the CIImage
. Here is the code:
let totalTransformationAndRotation = CGAffineTransform(rotationAngle: x)
// How I transform using the imageview
self.keyImage.transform = totalTransformationAndRotation
// How I transform using the image
var coreImage:CIImage? = myImage!.ciImage
if coreImage == nil {
coreImage = CIImage(cgImage: myImage!.cgImage!)
}
coreImage = coreImage?.transformed(by: totalTransformationAndRotation)
When used separately these two transformations come out totally differently. I understand that the unit is different for the CIImage
's transformation's dx and dy and UIImageView
's transformation's dx and dy, but even rotations have a different result. It appears to me that when rotated in the CIImage
. The rotation is centered around the bottom left, while in the UIImageView
it is centered around the center of the image.
Is it possible to rotate, scale and translate a UIImage/CIImage and have the same effect as if you applied the same transformations on a UIImageView?
Edit:
I am trying to transform a UIImage
by rotating, scaling, and translating. I have gotten the desired effect by applying a transforming on the UIImageView
's transform property but realized that I need to do the transformation directly in the image.
swift uiimageview core-image cgaffinetransform ciimage
swift uiimageview core-image cgaffinetransform ciimage
edited Nov 25 '18 at 20:14
joshLor
asked Nov 25 '18 at 19:17
joshLorjoshLor
485416
485416
There is no such thing as a UIImage transform. Your example involves CIImage, a very different thing. If you want help doing an image transformation please state clearly what the exact goal is. If you are just trying to draw the image rotated, I wouldn’t do it any of the ways you’ve shown so far.
– matt
Nov 25 '18 at 19:21
Thanks, @matt I fixed it.
– joshLor
Nov 25 '18 at 19:36
Ok but the CIImage is still not how I would do it. I would just redraw the image into an image graphics context with a transformed CTM. Again, I could demonstrate if you would be specific.
– matt
Nov 25 '18 at 19:43
Or see my discussion at apeth.com/iOSBook/ch15.html#_graphics_context_transforms
– matt
Nov 25 '18 at 19:49
@matt which one is faster? I may have to do hundreds of the transformations concurrently
– joshLor
Nov 25 '18 at 20:05
|
show 4 more comments
There is no such thing as a UIImage transform. Your example involves CIImage, a very different thing. If you want help doing an image transformation please state clearly what the exact goal is. If you are just trying to draw the image rotated, I wouldn’t do it any of the ways you’ve shown so far.
– matt
Nov 25 '18 at 19:21
Thanks, @matt I fixed it.
– joshLor
Nov 25 '18 at 19:36
Ok but the CIImage is still not how I would do it. I would just redraw the image into an image graphics context with a transformed CTM. Again, I could demonstrate if you would be specific.
– matt
Nov 25 '18 at 19:43
Or see my discussion at apeth.com/iOSBook/ch15.html#_graphics_context_transforms
– matt
Nov 25 '18 at 19:49
@matt which one is faster? I may have to do hundreds of the transformations concurrently
– joshLor
Nov 25 '18 at 20:05
There is no such thing as a UIImage transform. Your example involves CIImage, a very different thing. If you want help doing an image transformation please state clearly what the exact goal is. If you are just trying to draw the image rotated, I wouldn’t do it any of the ways you’ve shown so far.
– matt
Nov 25 '18 at 19:21
There is no such thing as a UIImage transform. Your example involves CIImage, a very different thing. If you want help doing an image transformation please state clearly what the exact goal is. If you are just trying to draw the image rotated, I wouldn’t do it any of the ways you’ve shown so far.
– matt
Nov 25 '18 at 19:21
Thanks, @matt I fixed it.
– joshLor
Nov 25 '18 at 19:36
Thanks, @matt I fixed it.
– joshLor
Nov 25 '18 at 19:36
Ok but the CIImage is still not how I would do it. I would just redraw the image into an image graphics context with a transformed CTM. Again, I could demonstrate if you would be specific.
– matt
Nov 25 '18 at 19:43
Ok but the CIImage is still not how I would do it. I would just redraw the image into an image graphics context with a transformed CTM. Again, I could demonstrate if you would be specific.
– matt
Nov 25 '18 at 19:43
Or see my discussion at apeth.com/iOSBook/ch15.html#_graphics_context_transforms
– matt
Nov 25 '18 at 19:49
Or see my discussion at apeth.com/iOSBook/ch15.html#_graphics_context_transforms
– matt
Nov 25 '18 at 19:49
@matt which one is faster? I may have to do hundreds of the transformations concurrently
– joshLor
Nov 25 '18 at 20:05
@matt which one is faster? I may have to do hundreds of the transformations concurrently
– joshLor
Nov 25 '18 at 20:05
|
show 4 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471004%2fdifference-between-cgaffinetransform-on-ciimage-and-uiimageview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471004%2fdifference-between-cgaffinetransform-on-ciimage-and-uiimageview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is no such thing as a UIImage transform. Your example involves CIImage, a very different thing. If you want help doing an image transformation please state clearly what the exact goal is. If you are just trying to draw the image rotated, I wouldn’t do it any of the ways you’ve shown so far.
– matt
Nov 25 '18 at 19:21
Thanks, @matt I fixed it.
– joshLor
Nov 25 '18 at 19:36
Ok but the CIImage is still not how I would do it. I would just redraw the image into an image graphics context with a transformed CTM. Again, I could demonstrate if you would be specific.
– matt
Nov 25 '18 at 19:43
Or see my discussion at apeth.com/iOSBook/ch15.html#_graphics_context_transforms
– matt
Nov 25 '18 at 19:49
@matt which one is faster? I may have to do hundreds of the transformations concurrently
– joshLor
Nov 25 '18 at 20:05