gpt4 book ai didi

ios - 按位命令产生错误访问错误

转载 作者:行者123 更新时间:2023-11-29 03:29:31 26 4
gpt4 key购买 nike

我正在编写一个应用程序以将图像信息隐藏到另一个图像中!我通过从第一张图像中删除 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(Code = 2” and Address ...)

我需要知道为什么这个错误会出现在一些图片中,我该如何解决。

谢谢...

最佳答案

其中的某些内容可能为零。有最可能的解释。请登出控制台您的steganoPixelData 。我很确定它可能为零,因为您的操作是允许的,并且您在这个方程中只有一个数据结构:steganoPixelData[index + red] <<= 0x4

也许你的形象为零?检查一下。有些东西可能被释放了。

关于ios - 按位命令产生错误访问错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19997558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com