johnnous
Messages postés100Date d'inscriptionjeudi 3 mars 2005StatutMembreDernière intervention24 mai 2013
-
12 mars 2010 à 13:07
yohan49
Messages postés380Date d'inscriptionsamedi 22 janvier 2005StatutMembreDernière intervention13 août 2011
-
22 mars 2010 à 20:56
bonjour
j'ai un petit soucis
j'ai une picturebox avec une image de font
sur celle ci j'ajoute d'autre picturebox fille
je dois pouvoir deplace et faire tourne mes picturebox en gérant la transparence
mom pb est que si une de mes picturebox fille passe sur une autre la transparence ne fonctionne pas
donc je me suis dit je vais faire une capture d'image CopyFromScreen et recharge ma picturebox avec la nouvelle image de font
mais je dois faire avant de faire ma capture disparaitre le picturebox active donc je la rend pas visible
mais si je fait ma capture à ce moment elle est présente dans la capture, et je ne sais pas quelle evenement me dit que la picturebox n'est plus visible j'ai essayer avec paint ou onvisiblechanged mais cela ne marche pas
quelqu'un aurrais une actuce
voici les sources
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
namespace RotateImage
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.OpenFileDialog ofd;
private Bitmap img = null;
private System.Windows.Forms.Button loadImage;
private System.Windows.Forms.NumericUpDown angle;
private System.Windows.Forms.PictureBox pictureBox;
private PictureBox MyPictureBox;
private Button bCopyImg;
private Button button1;
private PictureBox pictureBox1;
private NumericUpDown numericUpDown1;
private PictureBox PicConv;
private PictureBox pictureBox2;
private Button button2;
private NumericUpDown numericUpDown2;
private PictureBox pictureBox3;
private NumericUpDown numericUpDown3;
private PictureBox pictureBox4;
private Button button3;
Bitmap bitmap = new Bitmap(this.MyPictureBox.Width, this.MyPictureBox.Height, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
Point p = this.PointToScreen(this.MyPictureBox.Location);
g.CopyFromScreen(p.X, p.Y, 0, 0, this.MyPictureBox.Size, CopyPixelOperation.SourceCopy);
g.Dispose();
}
***************************************
la classe utilities
*****************************************
using System;
using System.Drawing;
namespace RotateImage
{
/// <summary>
/// Summary description for Utilities.
/// </summary>
public sealed class Utilities
{
private Utilities()
{
}
/// <summary>
/// Creates a new Image containing the same image only rotated
/// </summary>
/// The <see cref="System.Drawing.Image"/> to rotate
/// The amount to rotate the image, clockwise, in degrees
/// <returns>A new <see cref="System.Drawing.Bitmap"/> that is just large enough
/// to contain the rotated image without cutting any corners off.</returns>
/// <exception cref="System.ArgumentNullException">Thrown if <see cref="image"/> is null.</exception>
public static Bitmap RotateImage(Image image, float angle)
{
if(image == null)
throw new ArgumentNullException("image");
const double pi2 = Math.PI / 2.0;
// Why can't C# allow these to be const, or at least readonly
// *sigh* I'm starting to talk like Christian Graus :omg:
double oldWidth = (double) image.Width;
double oldHeight = (double) image.Height;
// Ensure theta is now [0, 2pi)
while( locked_theta < 0.0 )
locked_theta += 2 * Math.PI;
double newWidth, newHeight;
int nWidth, nHeight; // The newWidth/newHeight expressed as ints
#region Explaination of the calculations
/*
* The trig involved in calculating the new width and height
* is fairly simple; the hard part was remembering that when
* PI/2 <= theta <= PI and 3PI/2 <= theta < 2PI the width and
* height are switched.
*
* When you rotate a rectangle, r, the bounding box surrounding r
* contains for right-triangles of empty space. Each of the
* triangles hypotenuse's are a known length, either the width or
* the height of r. Because we know the length of the hypotenuse
* and we have a known angle of rotation, we can use the trig
* function identities to find the length of the other two sides.
*
* sine = opposite/hypotenuse
* cosine = adjacent/hypotenuse
*
* solving for the unknown we get
*
* opposite = sine * hypotenuse
* adjacent = cosine * hypotenuse
*
* Another interesting point about these triangles is that there
* are only two different triangles. The proof for which is easy
* to see, but its been too long since I've written a proof that
* I can't explain it well enough to want to publish it.
*
* Just trust me when I say the triangles formed by the lengths
* width are always the same (for a given theta) and the same
* goes for the height of r.
*
* Rather than associate the opposite/adjacent sides with the
* width and height of the original bitmap, I'll associate them
* based on their position.
*
* adjacent/oppositeTop will refer to the triangles making up the
* upper right and lower left corners
*
* adjacent/oppositeBottom will refer to the triangles making up
* the upper left and lower right corners
*
* The names are based on the right side corners, because thats
* where I did my work on paper (the right side).
*
* Now if you draw this out, you will see that the width of the
* bounding box is calculated by adding together adjacentTop and
* oppositeBottom while the height is calculate by adding
* together adjacentBottom and oppositeTop.
*/
#endregion
// We need to calculate the sides of the triangles based
// on how much rotation is being done to the bitmap.
// Refer to the first paragraph in the explaination above for
// reasons why.
if( (locked_theta >= 0.0 && locked_theta < pi2) ||
(locked_theta >= Math.PI && locked_theta < (Math.PI + pi2) ) )
{
adjacentTop = Math.Abs(Math.Cos(locked_theta)) * oldWidth;
oppositeTop = Math.Abs(Math.Sin(locked_theta)) * oldWidth;
Bitmap rotatedBmp = new Bitmap(nWidth, nHeight);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using(Graphics g = Graphics.FromImage(rotatedBmp))
{
// This array will be used to pass in the three points that
// make up the rotated image
Point [] points;
/*
* The values of opposite/adjacentTop/Bottom are referring to
* fixed locations instead of in relation to the
* rotating image so I need to change which values are used
* based on the how much the image is rotating.
*
* For each point, one of the coordinates will always be 0,
* nWidth, or nHeight. This because the Bitmap we are drawing on
* is the bounding box for the rotated bitmap. If both of the
* corrdinates for any of the given points wasn't in the set above
* then the bitmap we are drawing on WOULDN'T be the bounding box
* as required.
*/
if( locked_theta >= 0.0 && locked_theta < pi2 )
{
points = new Point[] {
new Point( (int) oppositeBottom, 0 ),
new Point( nWidth, (int) oppositeTop ),
new Point( 0, (int) adjacentBottom )
};
}
else if( locked_theta >= pi2 && locked_theta < Math.PI )
{
points = new Point[] {
new Point( nWidth, (int) oppositeTop ),
new Point( (int) adjacentTop, nHeight ),
new Point( (int) oppositeBottom, 0 )
};
}
else if( locked_theta >= Math.PI && locked_theta < (Math.PI + pi2) )
{
points = new Point[] {
new Point( (int) adjacentTop, nHeight ),
new Point( 0, (int) adjacentBottom ),
new Point( nWidth, (int) oppositeTop )
};
}
else
{
points = new Point[] {
new Point( 0, (int) adjacentBottom ),
new Point( (int) oppositeBottom, 0 ),
new Point( (int) adjacentTop, nHeight )
};
}
g.DrawImage(image, points);
}
int tmp = image.Width;
int tmp2 = image.Height;
return rotatedBmp;
}
}
}