I studied about a bit map at yesterday.
I understood a algorithm about the bitmap.
See code and
explanation below.
*****************************************************************************
//This method is invoked when choose button clicked- (void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingImage:(UIImage*)image
editingInfo:(NSDictionary*)editingInfo
{
//Restore the buttons statusButton.hidden = NO;
colorButton.hidden = NO;
fillColorButton.hidden = NO;
doneButton.hidden = NO;
allClearButton.hidden = NO;
layer1ClearButton.hidden = NO;
layer2ClearButton.hidden = NO;
layer3ClearButton.hidden = NO;
saveButton.hidden = NO;
loadButton.hidden = NO;
//Hide an ImagePickerView [self dismissModalViewControllerAnimated:YES];
//Create a new UIImage object(originalImage) and substitude originalImage for choose Image. UIImage* originalImage;
originalImage = [editingInfo objectForKey:UIImagePickerControllerOriginalImage];
//Create a new CGSize object(size) and initize it.it size is full screen size. CGSize size = { 320, 480 };
//Creates a bitmap-based graphics context and makes it the current context. UIGraphicsBeginImageContext(size);
//create a CGRect object for use drawInRect CGRect rect;
rect.origin = CGPointZero;//(0, 0)
rect.size = size;
[originalImage drawInRect:rect];
//Get an image by use UIGraphicsGetImageFromCurrentImageContext method. //this method is Returns an image based on the contents of the current bitmap-based graphics context. shrinkedImage = UIGraphicsGetImageFromCurrentImageContext();
//Removes the current bitmap-based graphics context from the top of the stack. UIGraphicsEndImageContext();
//create the CGIMageRef(cgImage) object and institute cgImage for shrinkedImage.CGImage. //CGImage is UIImage class property. CGImageRef cgImage;
cgImage = shrinkedImage.CGImage;
// get an information about image //__SIZE_TYPE__ is macro and iqual to unsigned int //typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */ //typedef __darwin_size_t size_t; unsigned int width;
//320 size_t height;
//480 size_t bitsPerComponent;
//8 size_t bitsPerPixel;
//32 size_t bytesPerRow;
//1280 = 4byte*320 CGColorSpaceRef colorSpace;
CGBitmapInfo bitmapInfo;
//8193 bool shouldInterpolate;
//true CGColorRenderingIntent intent;
//14081600 width = CGImageGetWidth(cgImage);
height = CGImageGetHeight(cgImage);
bitsPerComponent = CGImageGetBitsPerComponent(cgImage);
bitsPerPixel = CGImageGetBitsPerPixel(cgImage);
bytesPerRow = CGImageGetBytesPerRow(cgImage);
colorSpace = CGImageGetColorSpace(cgImage);
bitmapInfo = CGImageGetBitmapInfo(cgImage);
shouldInterpolate = CGImageGetShouldInterpolate(cgImage);
//Returns the interpolation setting for a bitmap image. intent = CGImageGetRenderingIntent(cgImage);
//Returns the rendering intent setting for a bitmap image. /*kCGRenderingIntentDefault, kCGRenderingIntentAbsoluteColorimetric, kCGRenderingIntentRelativeColorimetric, kCGRenderingIntentPerceptual, kCGRenderingIntentSaturation*/ // Create a dataProvider object and get a data provider CGDataProviderRef dataProvider;
// which you use to move data into and out of Quartz. // CGDataProviderRef allow you to supply Quartz functions with data. dataProvider = CGImageGetDataProvider(cgImage);
//Returns the data provider for a bitmap image.//get an information about bit map datas CFDataRef data;
data = CGDataProviderCopyData(dataProvider);
//data = 614400byte = 153600(320*480)*4 //Returns a copy of the provider’s data. //A reference to an immutable CFData object. UInt8* buffer;
//buffer is a pointer to UItnt8 //typedef unsigned char UInt8; buffer = (UInt8*)CFDataGetBytePtr(data);
//Returns a read-only pointer to the bytes of a CFData object. // give the effect of change color per pixel NSUInteger i, j;
for (j = 0; j < i =" 0;" style="font-weight: bold; font-style: italic; color: rgb(255, 0, 0);"> // get the pointer information
/*address space↓↓↓// //___________// //1pixel// //___________// //blue // //___________// //green // //___________// //red // //___________// //next pixel // //___________// //blue // //. // //. // //. */ UInt8* tmp;
tmp = buffer + j * bytesPerRow + i * 4;
//tmpはbufferのメモリ空間を頭から4バイトずつ移動しながらピクセルに効果を与えている。 // RGBの値を取得する UInt8 r, g, b;
r = *(tmp + 3);//r
g = *(tmp + 2);//g
b = *(tmp + 1);//b
// 輝度値を計算する UInt8 y;
y = (77 * r + 28 * g + 151 * b) / 256;
//重み付きの平均値 /* この重み付きの平均値 gray は輝度と呼ばれるもので、カラーテレビの信号処理 に使われます。輝度は色の明るさを表します。 重みを付けて平均を取るのは、人の視覚は赤・緑・青に対してそれぞれ感度が異 なるためで、 青 < 赤 < 緑 の順に感度が高くなります。最も感度の高い色に重みを持たせています。 http://www.asahi-net.or.jp/~uc3k-ymd/Glib32/loadbmp.html*/ // 輝度の値をRGB値として設定する /*********ネガポジ************ *(tmp + 1) = 255-b;//b *(tmp + 2) = 255-g;//g *(tmp + 3) = 255-r;//r ***************************/ *(tmp + 3) = 0;//r
*(tmp + 2) = g;//g
*(tmp + 1) = 0;//b
}
}
*****************************************************************************
I could get the pixel data of image and various effect to image.
for example gray scale nega
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1I9ZoNfY8AlBUAwTqpfBoAzak-2DJIBHFOhjrqHeSI-TSC-QiEZyPAa78szXLGKiPUHmYXu5svSTig6YhnowHCRZuytZlRiDlWTEdPgRjpTUR0ADU2s_JUAzjGo_mj7Nqh8mwFl5R_AiH/s200/Picture+20.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTkRmEqutig5BhkAdk2_aKcQkLUqNA24meynhyS6MiKb27IXKGZb_ZdlQXD_Hpj0tohOSBWOP5HgrjIlRP9H8MkPETzpdL9_eJIMHPMGAZuSm-i2ZDO_ia-1NNfmgB5vLuOf47bg_2MQpz/s200/Picture+19.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7JHqPTViycgPmQKNRtmlI_H1f6MFxVilf1zavgabVrYLcjTtkt6WpmKCeVERLOIrY4TegWY2xndnZTu9DEYV3osAvVXAfKpcWJ00Clem-97DULIdz_jxJVG62P2DOUEX8YJU62ZzPE2qz/s200/Picture+18.png)
I couldn't understand some a method.((UInt8*)CFDataGetBytePtr(data);)
I'll understand it.