- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
编辑答案:
- (UIImage*) maskImage:(UIImageView *)maskImage withMask:(UIImageView *)cropImage
{
UIImage *image = nil;
UIImage *imagePNG = nil;
CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0); //retina res
[self.viewForImg.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
NSData *imgData = UIImagePNGRepresentation ( image ); // get PNG representation
imagePNG = [UIImage imageWithData:imgData]; // wrap UIImage around PNG representation
UIGraphicsEndImageContext();
return imagePNG;
}
我尝试截取我的 iPhone 屏幕以将图片保存到我的相机胶卷中。但是遇到了这个错误。有人知道我的代码是否有问题吗?
May 22 14:13:34 unknown assetsd[281] <Error>: ImageIO: CGImageDestinationAddImage image parameter is nil
May 22 14:13:34 unknown assetsd[281] <Error>: ImageIO: CGImageDestinationFinalize image destination does not have enough images
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetBaseCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSaveGState: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextFillRects: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
代码:
- (IBAction)saveImage:(id)sender {
self.imageOverlay.alpha = 1;
self.savedImage = [self maskImage:self.imgView withMask:self.baseImgView];
UIImageWriteToSavedPhotosAlbum(self.savedImage, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}
- (UIImage*) maskImage:(UIImageView *)maskImage withMask:(UIImageView *)cropImage
{
UIImage *image = nil;
UIImage *imagePNG = nil;
CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0); //retina res
[self.viewForImg.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imgData = UIImagePNGRepresentation ( image ); // get PNG representation
imagePNG = [UIImage imageWithData:imgData]; // wrap UIImage around PNG representation
return imagePNG;
}
最佳答案
如果您传递给 UIGraphicsBeginImageContextWithOptions
的 CGSize
是 CGSizeZero
,则可能会发生这种情况。我假设 cropImage
参数是 nil
或其大小是 CGSizeZero
。请调试并确保您已初始化所有对象并使用正确的帧。
关于iPhone 屏幕截图错误。 <错误> : ImageIO: CGImageDestinationFinalize image destination does not have enough images,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10696734/
在javax.imageio.ImageIO中,有一个方法#write(RenderedImage im, String formatName, OutputStream output),它接受开发人
我对此问题感到非常困惑。我在jai-imageio-core上使用的是1.3.0版本,请检查下面的依赖关系,我完全不知道如何从jar中找出如何在JVM中加载一个类文件(RawImageReaderSp
我的应用程序正在将图像保存到文件夹中。同时另一个软件监视该文件夹并打印粘贴的图像。 我遇到的问题是打印应用程序可以在打印机上发送一半渲染的图像,或者根本不对保存的图像使用react。 我正在使用 ja
在下面的代码片段中,我尝试使用 javax.imageio.ImageIO 设置我的 JFrame 实例的图标,但出现以下异常。你能告诉我我缺少什么吗? import javax.imagei
我正在尝试将 Spring Web 应用程序部署到在 Windows Azure 上的生产环境中运行的 Tomcat 7(尝试过 Ubuntu 和 Windows Datacenter VM)。遗憾的
在使用套接字通过网络传输图像时,我遇到了一个奇怪的问题: 当我使用 ImageIO.write() 将图像写入一个套接字的 OutputStream 并使用 ImageIO.write() 从另一个套
下面您将看到一张来自土耳其的名为“simit”的精美糕点图片。它取自 iPad 2,因此它是尺寸为 720*960 的 JPEG。 问题是,当我使用 javax.imageio.ImageIO.rea
我在 Tomcat 5.5 中有一个 Servlet,它读取文件夹中的本地镜像。然后将图像发送回 Applet。 我收到此消息“javax.imageio.IIOException:无法创建 Imag
我有一张图片,称之为 grayscale.jpg。现在我在 The Gimp 中打开该图像并将颜色模式更改为 RGB 并将其保存为 color.jpg。如果我在任何图像查看器中查看 grayscale
这个问题在这里已经有了答案: Can't import javax.imageio.ImageIO in Android application (1 个回答) 关闭 9 年前。 当我试图做的时候,
我想将 Canvas 对象保存为图像,为此我想使用 ImageIO 类。我正在使用 Eclipse,但是当我尝试导入此库时(导入 javax.imageio.ImageIO;)Eclipse 向我显示
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws IOExceptio
我正在尝试通过套接字发送图像,但我遇到了一个奇怪的问题。ImageIO.write 发送的数据比 ImageIO.read 接收的数据多。例如,如果我在循环中有以下代码: (客户端) out.writ
我在 python 中处理一些图像,我正在尝试将一系列大小为 961x509 的图像转换为 MP4 电影文件。我已经这样做了并且它正在工作但是我有一个非常烦人的问题,警告说是这样的: WARNING:
Apple 的图像 I/O 编程指南说道: Image I/O resides in the Application Services framework in Mac OS X, and in th
我一直在开发一个程序,其中使用来自此 API (musicg) 的代码:http://code.google.com/p/musicg/ 但是,我的代码中仍有一部分给我带来了麻烦(GraphicRen
我无法加载 JAI 1.3.0 的 ImageIO 类。 Java 6 和 Web 应用程序服务器 (WAS) 8.5。我的代码适用于 Java 6 和 WAS(7.0.19)。 我已经在 pom.x
我一直在使用 javax.imageio.ImageIO 中的 ImageIO.read() 和 ImageIO.write() 方法来读取和写入图像,我发现有些图像的颜色发生了奇怪的变化。 即使我将
如果图像不是RGB颜色,如何解码图像。它应该通过支持所有格式(Jpg、Png、Gif来解码图像) code>..etc) 任何 api 都可以解码。 这是失败的代码行。那么可以使用哪种方法来解决该问题
以下测试在 Java 9 上失败,而在 Java 8 中通过: @Test public void getImage_SetValueUsingConstructor_ShouldReturnCorr
我是一名优秀的程序员,十分优秀!