bcb数字图像处理问题
小弟用下面的代码处理图片再保存到硬盘上!不知道为什么总是报“w8018错误 Assigning unsigned long to TColor”警告错误!我吧“bitmap->Canvas->Pixels[i][j]=RGB (red,green,blue);
”行代码删除就不报错了!
而且我用这段代码处理好的图片,可以用ACDsee打开正常,可用PhotpShop打开就报“不能打开E:\\投影仪电影\\图片保存\\1.bmp图片,应为文件格式模块不能解析该文件”!
真不知道错在哪里!请高手知道!小弟感激万分!
#include <vcl.h>
#pragma hdrstop
#include<jpeg.hpp>
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
struct rgb_str
{
unsigned char r_color;
unsigned char g_color;
unsigned char b_color;
};
rgb_str rgb[2500][1000];
int i,j,width,height;
Graphics::TBitmap *bitmap;
//---------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
int PelsWidth = GetSystemMetrics(SM_CXSCREEN);
int PelsHeight = GetSystemMetrics(SM_CYSCREEN);
Form1->Width=PelsWidth ;
Form1->Height=PelsHeight;
}
//---------------------------------------
void __fastcall TForm1::x1Click(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------
void __fastcall TForm1::Open1Click(TObject *Sender)
{
TColor color;
if(OpenPictureDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
width=Image1->Picture->Width;
height=Image1->Picture->Height;
for(i=0;i< width-1;i++)
for(j=0;j< height-1;j++)
{
color=Image1->Canvas->Pixels[i][j];
rgb[i][j].r_color=GetRValue(color);
rgb[i][j].g_color=GetGValue(color);
rgb[i][j].b_color=GetBValue(color);
}
bitmap=new Graphics::TBitmap;
bitmap->Width=width*3;
bitmap->Height=height;
}
}
//---------------------------------------
//第一台投影机播放 (单片)
void __fastcall TForm1::N2Click(TObject *Sender)
{
int red,green,blue;
for(i=1;i<width*3;i++)
{
for(j=1;j<height;j++)
{
if(i>width)
{
bitmap->Canvas->Pixels[i][j]=RGB(0,0,0);
}
else
{
red=rgb[i][j].r_color;
green=rgb[i][j].g_color;
blue=rgb[i][j].b_color;
bitmap->Canvas->Pixels[i][j]=RGB (red,green,blue);
}
}
}
Image1->Picture->Bitmap->Assign(bitmap);
bitmap->SaveToFile("E:\\投影仪电影\\图片保存\\1.bmp");
}
[解决办法]
你最后用这保存试试,不过我估计效果应该一样。
Image1->Picture->Bitmap->SaveToFile("E:\\投影仪电影\\图片保存\\1.bmp");
你上面的代码看不出问题,你确定你的图片是用上面的代码生成的?
你仔细回顾下你的操作,感觉问题不在上面的代码上。