在我的应用程序中,我需要调整大小并裁剪一些本地和在线存储的图像.我正在使用Trevor Harmon的教程实现UIImage+Resize.
在我的iPhone 4(iOS 4.3.1)上一切正常,我没有问题.但是在我的iPhone 3G(iOS 3.2)上,调整大小和裁剪方法对任何图片都不起作用(本地存储的是PNG).这是控制台输出:
Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes/row.
Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes/row.
Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes/row.
Tue Apr 5 …Run Code Online (Sandbox Code Playgroud) 在使用OpenCV时,我需要将NSImage转换为OpenCV多通道2D矩阵(cvMat),反之亦然.
最好的方法是什么?
迎接,
Dom
我一直在试图弄清楚如何将一组rgb像素数据转换为Swift中的UIImage.
我将每个像素的rgb数据保存在一个简单的结构中:
public struct PixelData {
var a: Int
var r: Int
var g: Int
var b: Int
}
Run Code Online (Sandbox Code Playgroud)
我已经开始使用以下函数,但生成的图像不正确:
func imageFromARGB32Bitmap(pixels:[PixelData], width: Int, height: Int)-> UIImage {
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo:CGBitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedFirst.rawValue)
let bitsPerComponent:Int = 8
let bitsPerPixel:Int = 32
assert(pixels.count == Int(width * height))
var data = pixels // Copy to mutable []
let providerRef = CGDataProviderCreateWithCFData(
NSData(bytes: &data, length: data.count * sizeof(PixelData))
)
let cgim = CGImageCreate(
width,
height,
bitsPerComponent,
bitsPerPixel,
width * Int(sizeof(PixelData)), …Run Code Online (Sandbox Code Playgroud) 我有一个CGMmage对象的NSMutableArray.所有图像都有不同的尺寸(80x20像素,200x200像素,10x10像素等等)我试图在CALayer中设置动画,其大小为256x256像素.动画有效,但是我的CGImages被拉伸到CALayer的尺寸.我怎么能阻止我的CGImages缩放?
谢谢.
我有一个相当大的,几乎全屏的图像,我将在iPad上显示.图像大约80%透明.我需要在客户端上确定不透明像素的边界框,然后裁剪到该边界框.
在StackOverflow上扫描其他问题并阅读一些CoreGraphics文档,我想我可以通过以下方式完成此任务:
CGBitmapContextCreate(...) // Use this to render the image to a byte array
..
- iterate through this byte array to find the bounding box
..
CGImageCreateWithImageInRect(image, boundingRect);
Run Code Online (Sandbox Code Playgroud)
这似乎非常低效和笨重.有没有什么聪明的我可以使用CGImage蒙版或利用设备的图形加速来做到这一点?
我想知道最有效的方法是制作带有图像的CALayer.
我知道你可以加载一个UIImage,然后调用[image CGImage],但这是最好的方法吗?据我所知,从Apple的文档中可以看出这是你能做到的唯一方法.
我正在为iPhone设计一个pixelate应用程序.因为使用iPhone 4相机拍摄的照片太大,因此在更新像素化图片时应用程序工作非常慢,我试图先创建图片的图块,然后更新图块而不是孔图片.
在构建图块时,它适用于以横向模式(2592 x 1936 pxl)和低分辨率图片拍摄的相机胶卷照片,但不适用于以纵向模式拍摄的照片(1936 x 2592 pxl).
从原始图像切割切片的代码如下所示:
for (i = 0; i < NrOfTilesPerHeight; i++) {
for (j = 0; j < NrOfTilesPerWidth; j++) {
CGRect imageRect = CGRectMake(j*TILE_WIDTH, i*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
CGImageRef image = CGImageCreateWithImageInRect(aux.CGImage, imageRect);
UIImage *img = [UIImage imageWithCGImage:image];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是用这些瓷砖创建的图像逆时针旋转到90度角.
非常感谢,Andrei
我一整天都在研究这个问题,并在SO和google上看了很多问题,但到目前为止我还没有提出任何正确的问题.
我在运行iOS 5.1.1的iPad上拍了一张照片,并使用照片应用裁剪了它.然后我从资产库中获取它的引用,并获得未裁剪的全分辨率图像.
我发现裁剪信息包含在我对象的AdjustmentXMP键中.metadataALAssetRepresentation
所以我使用XMP信息裁剪照片,这是我得到的:
原始照片(1,936 x 2,592):
正确裁剪的照片,如照片应用程序(1,420 x 1,938)中所示:
使用下面的代码裁剪照片
(也是1,420 x 1,938,但是在右边太远处裁剪了大约200像素):

这是照片中的XMP数据:
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:aas="http://ns.apple.com/adjustment-settings/1.0/">
<aas:AffineA>1</aas:AffineA>
<aas:AffineB>0</aas:AffineB>
<aas:AffineC>0</aas:AffineC>
<aas:AffineD>1</aas:AffineD>
<aas:AffineX>-331</aas:AffineX>
<aas:AffineY>-161</aas:AffineY>
<aas:CropX>0</aas:CropX>
<aas:CropY>0</aas:CropY>
<aas:CropW>1938</aas:CropW>
<aas:CropH>1420</aas:CropH>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Run Code Online (Sandbox Code Playgroud)
这是我用于裁剪照片的代码:
ALAssetRepresentation *rep = // Get asset representation
CGImageRef defaultImage = [rep fullResolutionImage];
// Values obtained from XMP data above:
CGRect cropBox = CGRectMake(0, 0, 1938, 1420);
CGAffineTransform transform = CGAffineTransformMake(1, 0, 0, 1, 331, 161);
// …Run Code Online (Sandbox Code Playgroud) 我能找到的所有代码都围绕将图像直接加载到可视控件中.
但是,我有自己的缓存系统(从另一种语言转换项目),所以我尽可能高效地想要以下内容:
我是swift和ios平台的新手,但据我所知,cgimage尽可能接近?但是,当使用cgimage时,似乎没有办法从文件系统加载图像...但是我发现人们正在讨论UIImage的方法,所以我现在怀疑我最初的印象ha cgimage是最好的匹配我的需要.
信息:使用Swift和CGImageSourceCreateWithURL函数.
我正在尝试从URL加载文件,然后编辑包含该特定照片中所有数据的字典.
这是.swift文件中的代码.
let url = NSURL(string: "http://jwphotographic.co.uk/Images/1.jpg")
let imageSource = CGImageSourceCreateWithURL(url, nil)
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary
println(imageProperties)
//this is an example
let aperture = imageProperties[kCGImagePropertyGPSLatitude] as! NSNumber!
/*
//these are all being defined as nil
//Load the ones from the exif data of the file
let lensUsed = imageProperties[kCGImagePropertyExifFocalLength]
let aperture = imageProperties[kCGImagePropertyExifApertureValue] as!
let isoSpeed = imageProperties[kCGImagePropertyExifISOSpeedRatings] as! NSNumber
let latitude = imageProperties[kCGImagePropertyGPSLatitude] as! NSNumber
let longitude = imageProperties[kCGImagePropertyGPSLongitude] as! NSNumber
let shutterSpeed = …Run Code Online (Sandbox Code Playgroud)