1 / 13

第7回 iPhone アプリ勉強会 画像処理クラスの作成 縣 禎輝

第7回 iPhone アプリ勉強会 画像処理クラスの作成 縣 禎輝. はじめに. 画像処理クラスの作成及び動作. 画像処理の流れ. Picker の作成 Interface の作成 Interface と接続. iPhone 上で画像選択. 画像情報の取得. 選択画像の取得 グラフィックスコンテキストの作成 画像の縮小・拡大. ビットマップデータの取得 RGB 値の取得 画像処理操作. 画像処理. 画像の描画. 処理画像の表示 作成データの解放. オフスクリーン描画. 直接画面に描写せず、

Download Presentation

第7回 iPhone アプリ勉強会 画像処理クラスの作成 縣 禎輝

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第7回iPhoneアプリ勉強会画像処理クラスの作成縣 禎輝

  2. はじめに • 画像処理クラスの作成及び動作

  3. 画像処理の流れ Pickerの作成 Interfaceの作成 Interfaceと接続 iPhone上で画像選択 画像情報の取得 選択画像の取得 グラフィックスコンテキストの作成 画像の縮小・拡大 ビットマップデータの取得 RGB値の取得 画像処理操作 画像処理 画像の描画 処理画像の表示 作成データの解放

  4. オフスクリーン描画 • 直接画面に描写せず、 イメージクラスのインスタンスに描画しておいて、処理後に画面に転送する という方法 メリット:再描画の際、処理時間が減る

  5. 画像の選択 -(void)imagePickerController:(UIImagePickerController*)picker  didFinishPickingImage:(UIImage*)image  editingInfo:(NSDictionary*)editingInfo • UIImageというクラスのオブジェクトがわたってくる • 第三の引数であるeditingInfo キーとしてUIImagePickerControllerOriginalImageを指定する事でオリジナルデータのUIImageオブジェクトを取り出す事ができる(画像サイズ1200×1600) 選択画像のクラス 画像サイズ320×320

  6. 画像情報の取得① // オリジナル画像を取得する UIImage*    originalImage; originalImage = [editingInfoobjectForKey:UIImagePickerControllerOriginalImage]; // グラフィックスコンテキストを作る(画像表示領域) CGSize  size = { 300, 400 }; UIGraphicsBeginImageContext(size); • グラフィックスコンテキスト グラフィックスを描画するための情報(描画属性)を格納しておくためのもので,これがないと画像の描画が行えない

  7. 画像情報の取得② // 画像を縮小して描画する CGRectrect; rect.origin = CGPointZero; rect.size = size;     [originalImagedrawInRect:rect]; • drawInRect(メソッド) 現在のコンテキストに対して、指定した大きさで画像の描画を行うもの // 描画した画像を取得する UIImage*    shrinkedImage; shrinkedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();

  8. 画像情報の取得③ • CGImage ・画像の詳細な情報を取得する事ができる(画像の幅、    高さ、ピクセルの要素毎のビット数、ピクセル毎の  ビット数、画像1行のバイト数)  ・UIImageオブジェクトから取り出す事ができる // CGImageを取得する CGImageRefcgImage; cgImage = shrinkedImage.CGImage; // 画像情報を取得する size_t                  width; size_t                  height; size_tbitsPerComponent; :

  9. ビットマップデータの取得 • CGDataProvider(オブジェクト) 画像の元データを取得する CGImageGetDataProviderで CGImageからCGDataProviderを取り出しCGDataProviderCopyData(API)で ビットマップデータを取得 // データプロバイダを取得する CGDataProviderRefdataProvider; dataProvider = CGImageGetDataProvider(cgImage);     // ビットマップデータを取得する CFDataRef   data;     UInt8*      buffer;     data = CGDataProviderCopyData(dataProvider);     buffer = (UInt8*)CFDataGetBytePtr(data);

  10. ビットマップデータの取得 • CFDataからポインタを取り出す NSUIntegeri, j;     for (j = 0; j < height; j++) {         for (i = 0; i < width; i++) {             // ピクセルのポインタを取得する             UInt8*  tmp; tmp = buffer + j * bytesPerRow + i * 4;             // RGBの値を取得する             UInt8   r, g, b;             r = *(tmp + 3);             g = *(tmp + 2);             b = *(tmp + 1);

  11. 画像処理 // 輝度値を計算する             UInt8   y;             y = (77 * r + 28 * g + 151 * b) / 256; //2値化 if(y < 118) y=0; else y=255;   // 輝度の値をRGB値として設定する             *(tmp + 1) = y;             *(tmp + 2) = y;             *(tmp + 3) = y;

  12. 画像の描画     // 効果を与えたデータを作成する CFDataRefeffectedData; effectedData = CFDataCreate(NULL, buffer, CFDataGetLength(data));   // 画像を作成する CGImageRefeffectedCgImage; UIImage*    effectedImage; effectedCgImage = CGImageCreate(             width, height,  bitsPerComponent, bitsPerPixel, bytesPerRow,  colorSpace, bitmapInfo, effectedDataProvider,              NULL, shouldInterpolate, intent); effectedImage = [[UIImagealloc] initWithCGImage:effectedCgImage];     [effectedImageautorelease];     // 画像を表示する     _imageView.image = effectedImage;

  13. おわりに • 画像処理クラスの作成及び動作

More Related