Graphics Drawimage method and Cropping

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Hi everyone,

I have a background image that is intended for full screen (240x320) apps.
The application can also run windowed (which is, I suppose, about 50 or so
pixels less in height).

When I use the Drawimage method, the image is stretched to fit even though I
specify a 240x320 rectangle. I am trying to figure out if it's possible to
crop it instead, so the start bar and menu bar essentially "hide" parts of
the image underneath. I know it's possible to crop the image to a certain
extent, but I can't figure out if it's possible to achieve this effect.

Alternatively, I could crop it manually and swap it appropriately, but
that's a pain.

Thanks!
Brian
 
Thank you Alex,

Do you know if there are issues then with drawing a rectangle larger than
the clientwidth/height?

Basically, my app has a screentap method that flips it between a maximized
window and a regular window. In both cases, I create a new bitmap of size
240x320 and draw the image and other strings. However, the client window
non-maximized is really something like 240x276 (roughly) -- so I'd expect a
little of the image to be cropped (which is what I want). But it stretches
it to fit these dimensions. Is it not supposed to? I can attach my code if
it helps...

Brian
 
Alex,

I actually did have a slight problem in the code, and fixing it did solve
the stretching problem.

But, I'm still trying to accomplish this effect: if the user taps the screen
to toggle full screen / window, I'd like the background image to stay
stationary.

The easy part is drawing the image in the full window, in a rectangle
240x320, at 0,0. But if you do the same while in a window, the image gets
drawn starting below the task bar; I suppose you could make the argument
that it is 0,0, but in reality for the screen it is more like 0,26. While
windowed, I'd like to crop the top 26 pixels, so, I tried (without much
hope) drawing a rectangle at 0,-26, with no joy.

Any ideas on how I can slap an image in a rectangle in this way?

Brian
 
Something like this:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
e.Graphics.DrawImage(bmpBG, e.ClipRectangle,
this.RectangleToScreen(e.ClipRectangle), GraphicsUnit.Pixel);
}
 
Back
Top