以下函数的目的是从文件加载的Bitmap中获取每个像素的R,G,B值,并将它们增加10.
## Set up your example data
df = read.table(text=" InvoiceDate CustomerID Invoice_Sum Number
1 '01/02/2011 08:23' 15240 312.900 14
2 '01/02/2011 08:31' 14911 797.770 45
3 '01/02/2011 09:01' 14496 234.470 14
4 '01/02/2011 09:36' 17147 409.500 18
5 '01/02/2011 09:38' 12626 -45.300 2
6 '01/02/2011 09:38' 17675 698.600 22
19 '01/02/2011 10:56' NA 669.460 88",
header=TRUE)
NeedID = which(is.na(df$CustomerID))
df$CustomerID[NeedID] =
sample(setdiff(10000:19999, df$CustomerID), length(NeedID))
但是,在检查保存文件时,亮度没有增加。我试图增加值,将每个R,G,B值更新为100,但图像保持不变,好像我没有正确设置新值。
任何人都可以告诉我我做错了什么吗?
编辑: 在遵循一些指导之后,我现在让图像变亮,但只增亮了四分之一的图像。
更改了代码
void PerformTransformation(Gdiplus::Bitmap* bitmap, LPCTSTR SaveFileName) {
Gdiplus::BitmapData* bitmapData = new Gdiplus::BitmapData;
UINT Width = bitmap->GetWidth();
UINT Height = bitmap->GetHeight();
Gdiplus::Rect rect(0, 0,Width,Height );
bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bitmapData);
byte* pixels = (byte*)bitmapData->Scan0;
INT iStride = abs(bitmapData->Stride);
for (UINT col = 0; col < Width; ++col)
for (UINT row = 0; row < Height; ++row)
{
unsigned int curColor = pixels[row * iStride / 4 + col];
int b = curColor & 0xff;
int g = (curColor & 0xff00) >> 8;
int r = (curColor & 0xff0000) >> 16;
if ((r + 10) > 255) r = 255; else r += 10;
if ((g + 10) > 255) g = 255; else g += 10;
if ((b + 10) > 255) b = 255; else b += 10;
pixels[curColor & 0xff ] = b;
pixels[curColor & 0xff00 >> 8] = g;
pixels[curColor & 0xff0000 >> 16] = r;
}
bitmap->UnlockBits(bitmapData);
CLSID pngClsid;
GetEncoderClsid(L"image/png", &pngClsid);
bitmap->Save(SaveFileName, &pngClsid, NULL);
}
答案 0 :(得分:0)