thisの質問と同じことをしたいと思います。 私のアプリケーションでは、FaceBookで画像を切り抜くように画像をトリミングしたいのですが、チュートリアルやサンプルコードのリンクを教えてください。私が提供したリンクは私の要求を完全に記述する。iPhoneで画像を切り抜く方法
答えて
任意のプロパティで新しい画像を作成できます。ここに私の機能、魔女はそれを行う。新しい画像の独自のパラメータを使用するだけです。私の場合、画像は切り取られず、元の場所から別の場所にピクセルを移動するだけで効果があります。あなたは別の高さと幅の新しいイメージを初期化する場合は、あなただけの新しいものに、あなたが必要とする古い画像の画素の任意の範囲からコピーすることができます
-(UIImage *)Color:(UIImage *)img
{
int R;
float m_width = img.size.width;
float m_height = img.size.height;
if (m_width>m_height) R = m_height*0.9;
else R = m_width*0.9;
int m_wint = (int)m_width; //later, we will need this parameters in float and int. you may just use "(int)" and "(float)" before variables later, and do not implement another ones
int m_hint = (int)m_height;
CGRect imageRect;
//cheking image orientation. we will work with image pixel-by-pixel, so we need to make top side at the top.
if(img.imageOrientation==UIImageOrientationUp
|| img.imageOrientation==UIImageOrientationDown)
{
imageRect = CGRectMake(0, 0, m_wint, m_hint);
}
else
{
imageRect = CGRectMake(0, 0, m_hint, m_wint);
}
uint32_t *rgbImage = (uint32_t *) malloc(m_wint * m_hint * sizeof(uint32_t));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rgbImage, m_wint, m_hint, 8, m_wint *sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetShouldAntialias(context, NO);
CGContextTranslateCTM(context, 0, m_hint);
CGContextScaleCTM(context, 1.0, -1.0);
switch (img.imageOrientation) {
case UIImageOrientationRight:
{
CGContextRotateCTM(context, M_PI/2);
CGContextTranslateCTM(context, 0, -m_wint);
}break;
case UIImageOrientationLeft:
{
CGContextRotateCTM(context, - M_PI/2);
CGContextTranslateCTM(context, -m_hint, 0);
}break;
case UIImageOrientationUp:
{
CGContextTranslateCTM(context, m_wint, m_hint);
CGContextRotateCTM(context, M_PI);
}
default:
break;
}
CGContextDrawImage(context, imageRect, img.CGImage);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
//here is new image. you can change m_wint and m_hint as you whant
uint8_t *result = (uint8_t *) calloc(m_wint * m_hint * sizeof(uint32_t), 1);
for(int y = 0; y < m_hint; y++) //new m_hint here
{
float fy=y;
double yy = (m_height*( asinf(m_height/(2*R))-asin(((m_height/2)-fy)/R) ))/
(2*asin(m_height/(2*R))); // (xx, yy) - coordinates of pixel of OLD image
for(int x = 0; x < m_wint; x++) //new m_wint here
{
float fx=x;
double xx = (m_width*( asin(m_width/(2*R))-asin(((m_width/2)-fx)/R) ))/
(2*asin(m_width/(2*R)));
uint32_t rgbPixel=rgbImage[(int)yy * m_wint + (int)xx];
int intRedSource = (rgbPixel>>24)&255;
int intGreenSource = (rgbPixel>>16)&255;
int intBlueSource = (rgbPixel>>8)&255;
result[(y * (int)m_wint + x) * 4] = 0;
result[(y * (int)m_wint + x) * 4 + 1] = intBlueSource;
result[(y * (int)m_wint + x) * 4 + 2] = intGreenSource;
result[(y * (int)m_wint + x) * 4 + 3] = intRedSource;
}
}
free(rgbImage);
colorSpace = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(result, m_wint, m_hint, 8, m_wint * sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast ); //new m_wint and m_hint as well
CGImageRef image1 = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIImage *resultUIImage = [UIImage imageWithCGImage:image1];
CGImageRelease(image1);
@try {
free(result);
}
@catch (NSException * e) {
NSLog(@"proc. Exception: %@", e);
}
return resultUIImage;
}
CGRect rectImage = CGRectMake(p1.x、p1.y 、p2.x-p1.x、p4.y-p1.y);
//Create bitmap image from original image data,
//using rectangle to specify desired crop area
CGImageRef imageRef = CGImageCreateWithImageInRect([imageForCropping CGImage], rectImage);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(p1.x, p1.y,p2.x-p1.x p4.y-p1.y)];
imageView1.image = croppedImage;
[self.view addSubview:imageView1];
CGImageRelease(imageRef);
ここでimageforcroppingは切り抜きたい画像です..そして切り取った部分を切り抜きたい画像 –
どんな考え方画像が回転しているとき(つまり、iphoneカメラから撮影したとき)にこの作業を行いますか? –
私はイメージをトリミングするときにイメージを回転させると思います!!!! –
- 1. iphone sdkで画像サークルを切り抜く方法
- 2. iphoneで特定の画像を切り抜く方法
- 3. エリアを選択してiPhoneで画像を切り抜く
- 4. C#で画像を切り抜く
- 5. プログラムで画像を切り抜く
- 6. Cで画像を切り抜く#
- 7. Javascriptで画像を切り抜く
- 8. CGImageRefで画像を切り抜く
- 9. 画像をCSSで切り抜く
- 10. 画像を手動で切り抜く
- 11. OpenCV C++で画像を切り抜く
- 12. %をベースにopencvとpythonで画像を切り抜く方法
- 13. opencvの記述ファイルで画像を切り抜く方法
- 14. ワードプレスのクラシファイドテーマからフロントエンドで画像を切り抜く方法
- 15. Androidで画像を切り抜く方法は?
- 16. jpg画像をPHPでのみ切り抜く方法は?
- 17. 画像を切り抜く/切り抜くことができません
- 18. ASP.NET C#:画像を切り抜く
- 19. PHP - 画像を切り抜くには?
- 20. Selenium webdriver nodejs - 画像を切り抜く方法
- 21. 画像を四角形に切り抜く方法
- 22. 中央の画像と切り抜く
- 23. jpeg画像からポリゴン画像を切り抜くJava
- 24. 指定された寸法内で画像を切り抜く方法
- 25. max-heightは下から画像を切り抜き、上から切り抜く方法は?
- 26. 画像を切り抜き、PHPでアップロード
- 27. テンソルフローで画像の切り抜きを使用する方法
- 28. カメラ2から長方形を切り抜く画像
- 29. 内部カメラクロッピングを使用しないで画像を切り抜く方法
- 30. 画像をキャプチャして切り抜き画像を切り抜いて保存画像
ご回答をありがとうセンチネルをしかし、私は事あなたは私、私はコード 'CGRect cropRect = CGRectMake(100、100、200、200)のこのラインをやっている私の画像をトリミングしたい質問を取得できませんでした; \t CGImageRef imageRef = CGImageCreateWithImageInRect(ImageREF.CGImage、cropRect);このクロッピングはハードコードされていますが、この[link](http://img192.imageshack.us/)に示されているイメージリンクのRectを調整します。 img192/8930/customcropbox.jpg) –
だから...あなたはちょうど画像をトリミングするためにrectを選択するために、ユーザーインターフェイスを作ることが欲しいですか?これは簡単です:ちょうどそこに動きに触れるを実装します。アルファ0.7の4つの白抜きバーは、切り抜かれる領域をミュートします。あなたは2つのタッチを扱うことができます:座標によると、それらがractangleの対角線の異なる側にあることを知って、あなたは簡単に4つの暗いバーのサイズを計算します。すべての動きでthamを変更してください。または、ワンタッチで:4つのスペース(青い円)が必要です。トラックをタッチしてそこに移動thamを移動する – SentineL
あなたのための応答SansLと応答方法と私は私をガイドしています:) –