473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Can't StretchBlt an image loaded from my hard drive

I can't seem to figure out why I can't StretchBlt an image that I have
loaded from my hard drive. There are two button events below. The first
button event, btnFormStretch_Click, works fine, but the second one,
btnStretch_Click, does not. The only difference seems to be the way that I
get the source graphic object. The first method uses the forms graphic
object whereas the second uses the Graphics.FromImage method. Any ideas?

[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll")]
public static extern bool StretchBlt(IntPtr hdcDest,
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int nHeightDest, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
System.Int32 dwRop // raster operation code
);

private void btnFormStretch_Click(object sender, System.EventArgs e)
{
Graphics gSource = this.CreateGraphics();
IntPtr dcSource = gSource.GetHdc();

Image bmpDest = new Bitmap(this.ClientRectangle.Width,
this.ClientRectangle.Height);
Graphics gDest = Graphics.FromImage(bmpDest);
IntPtr dcDest = gDest.GetHdc();

StretchBlt(dcDest, 0, 0, bmpDest.Width, bmpDest.Height,
dcSource, 0, 0, bmpDest.Width - 20, bmpDest.Height - 20, 0xCC0020);

gSource.ReleaseHdc(dcSource);
gDest.ReleaseHdc(dcDest);
bmpDest.Save(@"D:\Dave\TestImageCapture\Captured.b mp", ImageFormat.Bmp);
MessageBox.Show("Finished Saving Image");
}

private void btnStretch_Click(object sender, System.EventArgs e)
{
Bitmap bmpSource = new Bitmap(@"D:\Dave\TestImageCapture\Test2.bmp"); //
simple 16x16 bitmap
Graphics gSource = Graphics.FromImage(bmpSource);

Bitmap bmpDest = new Bitmap(32, 32); // double the size
Graphics gDest = Graphics.FromImage(bmpDest);
IntPtr dcSource = gSource.GetHdc();
IntPtr dcDest = gDest.GetHdc();

StretchBlt(dcDest, 0, 0, bmpDest.Width ,bmpDest.Height, dcSource, 0, 0,
bmpSource.Width, bmpSource.Height, 0xCC0020);

gSource.ReleaseHdc(dcSource);
gDest.ReleaseHdc(dcDest);

bmpDest.Save(@"D:\Dave\TestImageCapture\Captured.b mp", ImageFormat.Bmp);
MessageBox.Show("Finished Saving Image");
}
Thanks,
Dave
Nov 16 '05 #1
1 3655
My going to post this in microsoft.public.dotnet.framework.drawing since
nobody seems to know the answer here.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jess Lin | last post by:
Help! I am looking for a PHP function that when run, would save an image to the user's hard drive. -Jess
7
by: Bob L. | last post by:
Hi everyone, I am working on converting a VB6 project to .NET, and I am astounded at how amazingly slow Visual Studio is when loading a solution. For example, I have a solution with 11 class...
15
by: Tony Gahlinger | last post by:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7) to do some client-side image processing. I want to capture the sequence of coordinates a user clicks on in xxx.jpg in the...
7
by: Leszek | last post by:
Hello, I need to set dynamically height and width attributes of an image control on a WebForm. I know how to read the whole image from the hard-drive and use its height and width properties. I...
4
by: Fred Nelson | last post by:
I've written a VB.NET Web application that allows a user to upload a picture. Once the file has been uploaded, I have an editing process that allows the user to rotate the image 90 degrees...
4
by: Scott Glasgow | last post by:
I have the Microsoft Visual Basic .NET Deluxe Learning Edition from Microsoft and am trying to reinstall it after a hardware system crash requiring complete reformat/reinstall of Windows XP Pro and...
7
by: sonnystarks | last post by:
Page construction in progress: http://www.sdisplay.info/test/ Firefox does not recognize background image referred to on styles.css IE sees it with no problem. What is the problem? Thanx,
2
by: Steve Hershoff | last post by:
I'd like to display a jpeg image sitting on the C: drive of my webserver. The directory the image is under however, isn't beneath inetpub\wwwroot. Is there a way for an aspx page to display an...
2
by: Tim Streater | last post by:
The following test page is intended to allow the user to choose an image file, and then display it. It works as expected in Safari 3.1.1, FF 2.0.0.14 (Mac), and IE7 (XP). But, it fails in FF...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.