我正在编写一个应用程序以将图像信息隐藏到另一个图像中!我通过从第一个图像中删除 4 个低级别位并从第二个图像中添加 4 个高级别位来做到这一点!这是我的代码:
CGImageRef publicImage = _publicImageView.image.CGImage;
CFDataRef thePublicData;
thePublicData = CGDataProviderCopyData(CGImageGetDataProvider(publicImage));
UInt8 *publicPixelData = (UInt8 *) CFDataGetBytePtr(thePublicData);
int publicDataLength = CFDataGetLength(thePublicData);
//__________________________________________________________________________
CGImageRef secretImage = _secretImageView.image.CGImage;
CFDataRef theSecretData;
theSecretData = CGDataProviderCopyData(CGImageGetDataProvider(secretImage));
UInt8 *secretPixelData = (UInt8 *) CFDataGetBytePtr(theSecretData);
int secretDataLength = CFDataGetLength(theSecretData);
int red = 0;
int green = 1;
int blue = 2;
for (int index = 0 ; index < publicDataLength && index < secretDataLength; index +=4) {
uint pRed = publicPixelData [index + red] % 0x10;
publicPixelData [index + red] -= pRed;
uint sRed = secretPixelData [index + red] / 0x10;
publicPixelData[index + red] += sRed;
uint pGreen = publicPixelData [index + green] % 0x10;
publicPixelData [index + green] -= pGreen;
uint sGreen = secretPixelData [index + green] / 0x10;
publicPixelData[index + green] += sGreen;
uint pBlue = publicPixelData [index + blue] % 0x10;
publicPixelData [index + blue] -= pBlue;
uint sBlue = secretPixelData [index + blue] / 0x10;
publicPixelData[index + blue] += sBlue;
}
CGContextRef context;
context = CGBitmapContextCreate(publicPixelData,
CGImageGetWidth(publicImage),
CGImageGetHeight(publicImage),
8,
CGImageGetBytesPerRow(publicImage),
CGImageGetColorSpace(publicImage),
kCGImageAlphaPremultipliedLast);
CGImageRef newCGImage = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newCGImage];
CGContextRelease(context);
CFRelease(thePublicData);
CGImageRelease(newCGImage);
_hideEffectImageView.image = newImage;
为了恢复第二张图像,我将“__hideEffectImageView”数据的位移动到高级位置!
这是这段代码:
CGImageRef stganoImage = _hideEffectImageView.image.CGImage;
CFDataRef stganoData;
stganoData = CGDataProviderCopyData(CGImageGetDataProvider(stganoImage));
UInt8 *steganoPixelData = (UInt8 *) CFDataGetBytePtr(stganoData);
int publicDataLength = CFDataGetLength(stganoData);
//__________________________________________________________________________
// CGImageRef secretImage;
// CFDataRef theSecretData;
// UInt8 *secretPixelData = (UInt8 *)CFDataGetBytePtr(stganoData);
int red = 0;
int green = 1;
int blue = 2;
for (int index = 0 ; index < publicDataLength; index +=4) {
steganoPixelData [index + red] = steganoPixelData [index + red] << 0x4 ;
steganoPixelData [index + green] = steganoPixelData [index + red] << 0x4 ;
steganoPixelData [index + blue] = steganoPixelData [index + red] << 0x4 ;
}
CGContextRef context;
context = CGBitmapContextCreate(steganoPixelData,
CGImageGetWidth(stganoImage),
CGImageGetHeight(stganoImage),
8,
CGImageGetBytesPerRow(stganoImage),
CGImageGetColorSpace(stganoImage),
kCGImageAlphaPremultipliedLast);
CGImageRef newCGImage = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newCGImage];
CGContextRelease(context);
CFRelease(stganoData);
CGImageRelease(newCGImage);
_recoverSecretImage.image = newImage;
在某些图像中,我在代码“steganoPixelData [index + red] = steganoPixelData [index + red] << 0x4 ;”的行中得到“EXC_BAD_ACCESS(代码 = 2”和地址 ...)
我需要知道为什么此错误出现在某些图像中以及如何修复它。
那谢谢啦...