我正在研究天文学应用程序,我必须在PictureBox中显示科学16位FIT格式(单色)的图像。我正在与执行一些复杂天体测量的另一个DLL连接,并且还提供了FITS图片的缩放的8位DIB图像(没有chioce但是使用这个dll)。然而,它是用VB6编写的,它不适用于C#VS2010位图。我能够完成这项工作的唯一方法就是通过图形。 “PaintPicture”是执行转换的外部dll方法。问题是这种方法经常产生空白图像,特别是在调试模式时:
obs.FITSbmp = new Bitmap(obs.p.Columns, obs.p.Rows);
pictureBoxFITS.BackgroundImage = obs.FITSbmp;
obs.g = Graphics.FromImage(obs.FITSbmp);
//Have to go thru graphics as PP targets VB6
obs.pic.PaintPicture((int)obs.g.GetHdc());
obs.g.ReleaseHdc();
有没有人知道为什么会这样,更重要的是,如何解决这个问题?我在这里遗漏了什么,或者我做错了什么?
答案 0 :(得分:1)
这离我的专业领域很远,但这里有一些提示可能会有所帮助:
看起来你(和/或DLL)使用GDI。
你确定未转换的位图是否正确呈现?
[Edit1] VCL直接位图访问(BDS2006 C ++中的代码,所以你必须将* bmp的东西转换为VB风格)
//---------------------------------------------------------------------------
void bmp_example()
{
Graphics::TBitmap *bmp;
int **pyx=NULL,xs=0,ys=0;
// [init bitmap use]
bmp=new Graphics::TBitmap; // new VCL bitmap
bmp->HandleType=bmDIB; // is Device independent to allow direct access
bmp->PixelFormat=pf32bit; // i use 32 bit to match pixel with int/DWORD variable size
// here render/load data into bmp
bmp->Width=2500; // for example resize bmp to 128x128 pixels
bmp->Height=2500;
// create all neded for direct access
// must do this after any bitmap realloc/resize
// main idea is to store pointers into your own variables
// and access throu them instead of GDI to avoid checking slow-downs
if (pyx) delete pyx;
xs=bmp->Width; // xs,ys = actual bmp size
ys=bmp->Height;
bmp->HandleType=bmDIB; // is Device independent to allow direct access
bmp->PixelFormat=pf32bit; // i use 32 bit to match pixel with int/DWORD variable size
pyx=new int*[ys];
for (int y=0;y<ys;y++) // copy line pointers to pyx
pyx[y]=(int*)bmp->ScanLine[y];
// [direct access]
int x,y,*p;
for (y=0;y<ys;y++) // fill whole bmp
for (x=0;x<xs;x++)
{ // this will fill bmp with grayscale diagonal patern
pyx[y][x]=((x+y)&255)*0x00010101;
}
for (x=0;x<xs;x++) // does not mater which loop is first
for (y=0;y<ys;y++)
{ // this will fill bmp with grayscale diagonal patern
pyx[y][x]=((x+y)&255)*0x00010101;
}
for (y=0;y<ys;y++) // this is bit faster (but not by much and limitaccess to lines so y loop must be first)
{
p=pyx[y]; // acces just line to avoid 2D addresing
for (x=0;x<xs;x++)
{ // this will clear bmp with white color
p[x]=0x00FFFFFF;
}
}
// [exit btmap use]
if (bmp) delete bmp; bmp=NULL;
if (pyx) delete pyx; pyx=NULL;
}
//---------------------------------------------------------------------------
[编辑2]我还有另外一个想法可能是错的。
我看到您正在从DLL访问piantbox位图