本文整理汇总了C#中System.Windows.Media.Imaging.BitmapFrame类的典型用法代码示例。如果您正苦于以下问题:C# BitmapFrame类的具体用法?C# BitmapFrame怎么用?C# BitmapFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitmapFrame类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了BitmapFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JpgToBase64
public static string JpgToBase64(BitmapFrame aBMP)
{
try
{
string pBase64String = null;
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
//BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(aBMP);
MemoryStream ms = new MemoryStream();
//Convert.ToBase64String
encoder.Save(ms);
byte[] pPole = new byte[ms.Length];
ms.Seek(0, SeekOrigin.Begin);
ms.Read(pPole, 0, pPole.Length);
pBase64String = Convert.ToBase64String(pPole);
ms.Close();
return pBase64String;
}
catch (Exception)
{
return null;
}
}
示例2: DesignTimeSearchResult
public DesignTimeSearchResult(BitmapFrame icon, string processName, string title, string error = null)
{
View = new BasicListEntry();
Icon = icon;
ProcessName = processName;
Title = title;
Error = error;
}
示例3: ToByteArray
private static byte[] ToByteArray(BitmapFrame bfResize)
{
MemoryStream msStream = new MemoryStream();
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(bfResize);
encoder.Save(msStream);
return msStream.ToArray();
}
示例4: GetPngStream
private static MemoryStream GetPngStream(BitmapFrame photo)
{
MemoryStream result = new MemoryStream();
PngBitmapEncoder targetEncoder = new PngBitmapEncoder();
targetEncoder.Frames.Add(photo);
targetEncoder.Save(result);
return result;
}
示例5: ImageToByte
public static byte[] ImageToByte(BitmapFrame bfResize)
{
using (MemoryStream msStream = new MemoryStream())
{
PngBitmapEncoder pbdDecoder = new PngBitmapEncoder();
pbdDecoder.Frames.Add(bfResize);
pbdDecoder.Save(msStream);
return msStream.ToArray();
}
}
示例6: GetFramePixelDepth
/// <summary>
/// Gets the pixel depth (in bits per pixel, bpp) of the specified frame
/// </summary>
/// <param name="frame">The frame to get BPP for</param>
/// <returns>The number of bits per pixel in the frame</returns>
static int GetFramePixelDepth (BitmapFrame frame)
{
if (frame.Decoder.CodecInfo.ContainerFormat == new Guid("{a3a860c4-338f-4c17-919a-fba4b5628f21}")
&& frame.Thumbnail != null)
{
// Windows Icon format, original pixel depth is in the thumbnail
return frame.Thumbnail.Format.BitsPerPixel;
}
// Other formats, just assume the frame has the correct BPP info
return frame.Format.BitsPerPixel;
}
示例7: GenSheet
//Function to Gen the sprite sheet with a string of images
public void GenSheet(string[] images)
{
BitmapFrame[] frames = new BitmapFrame[images.Length];
// Atlas Dimensions
int iW = 0;
int iH = 0;
// Loads the images to tile (no need to specify PngBitmapDecoder, the correct decoder is automatically selected)
for (int i = 0; i < images.Length; i++)
{
frames[i] = BitmapDecoder.Create(new Uri(images[i]), BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.First();
}
//Make it so that the two biggest heights and widths depict size
for(int i = 0; i<frames.Length; i++)
{
iW += frames[i].PixelWidth;
}
for(int i = 1; i<frames.Length; i++)
{
iH = Math.Max(frames[i-1].PixelHeight, frames[i].PixelHeight);
}
// Draws the images into a DrawingVisual component
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext drawingContext = drawingVisual.RenderOpen())
{
int prevFrames = 0;//var prevFrames changed during loop
for (int i = 0; i < frames.Length; i++)
{
//loading all the images using a for loop for a finite number of images
drawingContext.DrawImage(frames[i], new Rect(prevFrames, 0, frames[i].PixelWidth, frames[i].PixelHeight));
//saves the width of the prevFrame so that the next image can draw next to it and produces a row of images
prevFrames += frames[i].PixelWidth;
}
}
// Converts the Visual (DrawingVisual) into a BitmapSource
RenderTargetBitmap bmp = new RenderTargetBitmap(iW, iH, 96, 96, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
// Creates a PngBitmapEncoder and adds the BitmapSource to the frames of the encoder
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
string directory = Directory.GetCurrentDirectory();
// Saves the image into a file using the encoder
using (Stream stream = File.Create(directory + @"\tile.png"))
encoder.Save(stream);
Vector[] eeek = stripSorter(frames);
XML eek = new XML();
eek.BuildXMLDoc(images, frames, iW, iH, eeek);
}
示例8: SetTile
public void SetTile(int _x, int _y, BitmapFrame _image)
{
// hat das bild noch keine ID?
if(!images.Contains(_image))
{
// id erstellen
images.Add(_image);
}
// id setzen
Tiles[_x, _y] = images.IndexOf(_image);
}
示例9: ToByteArrayWpf
public static byte[] ToByteArrayWpf(BitmapFrame targetFrame, int quality)
{
byte[] targetBytes;
using (var memoryStream = new MemoryStream()) {
var targetEncoder = new JpegBitmapEncoder {
QualityLevel = quality
};
targetEncoder.Frames.Add(targetFrame);
targetEncoder.Save(memoryStream);
targetBytes = memoryStream.ToArray();
}
return targetBytes;
}
示例10: Resize
private static BitmapFrame Resize(BitmapFrame photo, int width, int height, BitmapScalingMode scalingMode)
{
DrawingGroup group = new DrawingGroup();
RenderOptions.SetBitmapScalingMode(group, scalingMode);
group.Children.Add(new ImageDrawing(photo, new Rect(0, 0, width, height)));
DrawingVisual targetVisual = new DrawingVisual();
DrawingContext targetContext = targetVisual.RenderOpen();
targetContext.DrawDrawing(group);
RenderTargetBitmap target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);
targetContext.Close();
target.Render(targetVisual);
BitmapFrame targetFrame = BitmapFrame.Create(target);
return targetFrame;
}
示例11: CreateImageFile
private void CreateImageFile(FileStream file,BitmapFrame frame,ImageType type)
{
if(file==null)return;
BitmapEncoder encoder=null;
switch(type)
{
case ImageType.Bmp:encoder=new BmpBitmapEncoder();break;
case ImageType.Jpg:encoder=new JpegBitmapEncoder(){QualityLevel=100};break;
case ImageType.Png:encoder=new PngBitmapEncoder();break;
case ImageType.Gif:encoder=new GifBitmapEncoder();break;
case ImageType.Tiff:encoder=new TiffBitmapEncoder(){Compression=TiffCompressOption.Default};break;
}
encoder.Frames.Add(frame);
encoder.Save(file);
}
示例12: GetThumbnail
/// <summary>
/// ThumbnailExceptionWorkArround when image cause a format exception by accessing the Thumbnail
/// </summary>
/// <param name="frame"></param>
/// <returns></returns>
static BitmapSource GetThumbnail(BitmapFrame frame)
{
try
{
if (frame != null &&
frame.PixelWidth == 16 && frame.PixelHeight == 16 &&
((frame.Format == PixelFormats.Bgra32) || (frame.Format == PixelFormats.Bgr24)))
return frame;
else
return null;
}
catch (Exception)
{
return null;
}
}
示例13: ConvertToBitmapImage
private BitmapImage ConvertToBitmapImage(BitmapFrame bf)
{
BmpBitmapEncoder encoder = new BmpBitmapEncoder
{
Frames = { bf }
};
MemoryStream stream = new MemoryStream();
encoder.Save(stream);
stream.Seek(0L, SeekOrigin.Begin);
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.EndInit();
stream.Close();
return image;
}
示例14: AddToolboxImage
private void AddToolboxImage(BitmapFrame _image)
{
// neues bild erstellen
Image newImage = new Image();
// groesse des bildes festlegen
newImage.Width = 50.0f;
newImage.Height = 50.0f;
newImage.Margin = new Thickness(5.0d);
// event registrieren
newImage.MouseDown += Image_MouseDown;
// bildquelle angeben
newImage.Source = _image;
// bild der toolbox hinzufuegen
ToolBoxStackPanel.Children.Add(newImage);
}
示例15: Photo
/// <summary>
/// Constructor
/// </summary>
public Photo(string path, string name)
{
_source = new Uri(path);
_image = BitmapFrame.Create(_source);
//_name = name.Remove(name.Length - 4); //Remove fileextension
_name = Tools.RemoveExtension(name);
_name = Tools.RemoveStartNumber(_name);
//Create Thumbnail for png and Bmp images
if (_image.Thumbnail == null)
{
_myThumbnail = new BitmapImage();
_myThumbnail.BeginInit();
_myThumbnail.UriSource = _source;
_myThumbnail.DecodePixelWidth = 436;
_myThumbnail.DecodePixelHeight = 326;
_myThumbnail.EndInit();
}
}