C♯相談室 Part17
■ このスレッドは過去ログ倉庫に格納されています
0457437
NGNGpublic int SDrawPic(StringBuilder PicFile,PictureBox ToDraw)
{
IntPtr BitMapMemoryHandle = IntPtr.Zero;IntPtr BitMapInf = IntPtr.Zero; IntPtr LocalMemoryBMP;
int LocalMemoryInf; int Ret = 0; int Ret2;
BITMAPINFOHEADER BitMapHeader = new BITMAPINFOHEADER();
//画像展開
Ret = JPGDraw(PicFile, 0, 0,ref BitMapMemoryHandle,ref BitMapInf, 0, 0);
//メモリーのロック
LocalMemoryBMP = (IntPtr)LocalLock(BitMapMemoryHandle);
LocalMemoryInf = LocalLock(BitMapInf);
//ガベージコレクタがオブジェクトを移動できないようにする
GCHandle gch = GCHandle.Alloc(BitMapHeader, GCHandleType.Pinned);
GCHandle gch2 = GCHandle.Alloc(ToDraw.Image, GCHandleType.Pinned);
//メモリの移動
int address = gch.AddrOfPinnedObject().ToInt32();
MoveMemory((IntPtr)address,(IntPtr)LocalMemoryBMP,Marshal.SizeOf(BitMapHeader));
//描画準備
int address2 = gch.AddrOfPinnedObject().ToInt32();
Ret2 = SetDIBits(ToDraw.Handle, (IntPtr)address2, 0, ToDraw.Height,ref LocalMemoryInf,ref LocalMemoryBMP, 0);
if(Ret2 == 0) Ret = 11;
//メモリの開放
LocalUnlock(BitMapMemoryHandle);
LocalUnlock(BitMapInf);
LocalFree(BitMapMemoryHandle);
LocalFree(BitMapInf);
gch.Free();
gch2.Free();
//描画
ToDraw.Refresh();
return Ret;
}
■ このスレッドは過去ログ倉庫に格納されています