
I am trying to copy a bitmap image from a file to a picbox (on a form) using stretchblt. I am having and issue with getting the handle to the bitmap graphic.
I have included the entire code below (it is marked at line 38 where I think my issue is)
To execute it just build a new Windows Form project and add a button (button1) and a picture box (picturebox1)
then add a small bitmap image to your c:\ (root) named C:\test2.bmp
I have attached the .bmp file I used but any smaller .bmp file should work.
(BTW - I know there are other ways of doing what I ask but I MUST use the Strechblt command so other solutions can be ignored)
Thank You
I would appreciate any help...
the code to plug into the form follows...
START OF CODE_________________________________
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsTestBlt
{

public partial class Form1 : Form
{
/// StretchBlt
[DllImport("GDI32.DLL", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern bool StretchBlt(IntPtr hdcDest, int nXDest, int nYDest, int nDestWidth, int nDestHeight,
IntPtr hdcSrc, int nXSrc, int nYSrc, int nSrcWidth, int nSrcHeight, Int32 dwRop);
public Form1()
{
InitializeComponent();
}
public void renderTextLineFromBitmap()
{
//get bmp from a file
Bitmap bmp = (System.Drawing.Bitmap)Image.FromFile("C:\\test2.bmp");
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-31712-1.html
配上mv歌更好听
那里边演习的就是阿利伯克级导弹驱逐舰