Je dois faire pivoter une image qui est transmise à une fonction sous la forme d'un tableau de BitmapFrames. le produit fini doit également être sauvegardé en tant que BitmapFrame afin que je puisse l'envoyer à ma fonction Export-Image. Aidez-moi?Je dois faire pivoter une image
[Cmdlet(VerbsData.ConvertTo, "Rotate")]
public class RotateCmdlet : PSCmdlet
{
private BitmapFrame[] bFrame, outFrame;
private BitmapSource src;
private double pixelsize;
private int degrees;
private byte[] pixels, outPixels;
[Parameter(ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
public BitmapFrame[] Bitmap
{
get
{
return bFrame;
}
set
{
bFrame = value;
}
}
[Parameter(Position = 0), ValidateNotNullOrEmpty]
public int Degrees
{
get
{
return degrees;
}
set
{
degrees = value;
}
}
protected override void ProcessRecord()
{
base.ProcessRecord();
Console.Write("Rotating the image {0} degrees...\n\n", degrees);
outFrame = new BitmapFrame[bFrame.Length];
for (int c = 0; c < bFrame.Length; c++)
{
Image image;
pixelsize = bFrame[c].PixelWidth * bFrame[c].PixelHeight;
pixels = new byte[(int)pixelsize];
outPixels = new byte[(int)pixelsize];
bFrame[c].CopyPixels(pixels, (int)(bFrame[c].Width * (bFrame[c].Format.BitsPerPixel/8.0)), 0);
Stream strm = new MemoryStream(pixels);
image = Image.FromStream(strm);
var newBitmap = new Bitmap((int)bFrame[c].PixelWidth, (int)bFrame[c].PixelHeight);
var graphics = Graphics.FromImage(newBitmap);
graphics.TranslateTransform((float)bFrame[c].PixelWidth/2, (float)bFrame[c].PixelHeight/2);
graphics.RotateTransform(degrees);
graphics.TranslateTransform(-(float)bFrame[c].PixelWidth/2, -(float)bFrame[c].PixelHeight/2);
graphics.DrawImage(image, new System.Drawing.Point(0, 0));
for (int i = 0; i < pixelsize; i++)
{
outPixels[i] = pixels[i];
}
src = BitmapSource.Create(bFrame[c].PixelWidth, bFrame[c].PixelHeight, bFrame[c].DpiX, bFrame[c].DpiY,
bFrame[c].Format, bFrame[c].Palette, outPixels, (int)(bFrame[c].Width * (bFrame[c].Format.BitsPerPixel/8)));
outFrame[c] = BitmapFrame.Create(src);
}
WriteObject(outFrame);
}
}
Un peu plus d'infos serait bien :) Quel est le problème avec le code que vous avez posté, par exemple? – cwap
Aussi (pas pertinent à votre question) vous voulez appeler Dispose() sur tout ce que vous utilisez ici comme Stream, Bitmap et Graphics (ou utilisez-les dans un bloc using()). – MusiGenesis
Vous pourrez peut-être en déduire plus d'informations sur le problème de dabonz413 ici: http://www.stackoverflow.com/questions/1190743/ Je n'ai pas encore eu le temps de parcourir le code à fond, et j'ai posé cette question quelques semaines il y a quelque temps, donc je ne suis pas complètement fraîche. Mais je posterai à nouveau ici si je finis par trouver des informations plus utiles (ou contextuelles). – Giffyguy