0
私のアプリでは画像をキャプチャしてフレームを追加しています... 最終画像(オリジナル画像+フレーム)にカスタムテキストを追加する機能もあります。私はテキストを描画するために、次のコードを使用しています。iphoneの画像解像度がEメールで送信されました
-(UIImage *)addText:(UIImage *)img text:(NSString *)textInput
{
CGFloat imageWidth = img.size.width;
CGFloat imageHeigth = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, imageWidth, imageHeigth, 8,
4 * imageWidth, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, imageWidth, imageHeigth), img.CGImage);
CGContextSetCMYKFillColor(context, 0.0, 0.0, 0.0, 1.0,1);
CGContextSetFont(context, customFont);
UIColor * strokeColor = [UIColor blackColor];
CGContextSetFillColorWithColor(context, strokeColor.CGColor);
CGContextSetFontSize(context, DISPLAY_FONT_SIZE * DisplayToOutputScale);
// Create an array of Glyph's the size of text that will be drawn.
CGGlyph textToPrint[[textInput length]];
for (int i = 0; i < [textInput length]; ++i)
{
// Store each letter in a Glyph and subtract the MagicNumber to get appropriate value.
textToPrint[i] = [textInput characterAtIndex:i] + 3 - 32;
}
// First pass to be displayed invisible, will be used to calculate the length of the text in glyph
CGContextSetTextDrawingMode(context, kCGTextInvisible);
CGContextShowGlyphsAtPoint(context, 0 , 0 , textToPrint, [textInput length]);
CGPoint endPoint = CGContextGetTextPosition(context);
// Calculate position of text on white border frame
CGFloat xPos = (imageWidth/2.0f) - (endPoint.x/2.0f);
CGFloat yPos;
yPos = 30 * DisplayToOutputScale;
// Toggle off invisible mode, we are ready to draw the text
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextShowGlyphsAtPoint(context, xPos , yPos , textToPrint, [textInput length]);
// Extract resulting image
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
私はUIImageJPEGRepresentationを使用してメールを送信し、データを添付します。
カスタムテキストを追加せずに画像をメールすると、画像サイズが1050 x 1275から2100 x 2550に変わってしまいます。 しかし、テキストを追加して画像をメールすると、画像のサイズは変更されません。 これがなぜ起こるのか誰にでも説明できますか? UIImageからUIDataへの変換には何かがあると思います。
Thanx
網膜の表示(つまり、スケールプロパティ!= 1のUIImageオブジェクト)と関連していますか? – deanWombourne
それが事実ならば、それはテキストを伴う画像にも影響を与えるはずです。 – Tarang
ここに、ソリューションへのリンクhttp://www.iphonedevsdk.com/forum/iphone-sdk-development/71013-iphone-image-resolution-increased-when-emailed.html#post294505 – Tarang