在Silverlight应用程序中,我将BitmapImage定义为,System.Windows.Media.Imaging.BitmapImage并将其作为一个名为" SetSource" 的方法,我可以像这样设置源:
BitmapImage bitmap = new BitmapImage();
System.IO.Stream stream = _scene.GetStream();
if (stream == null) return;
bitmap.SetSource(stream);
Run Code Online (Sandbox Code Playgroud)
在WPF应用程序中,我还定义了一个Bitmap图像,System.Windows.Media.Imaging.BitmapImage但没有SetSource方法.如何像在Silverlight应用程序中那样在WPF应用程序中设置源代码?
此外,它是一个流,而不是一个字符串.它不是URI.所以"UriSource"方法不起作用.我试过这个:
System.IO.Stream stream = _scene.GetStream();
if (stream == null) return;
BitmapImage bitmap = new BitmapImage();
bitmap.UriSource = new Uri(stream.ToString());
Run Code Online (Sandbox Code Playgroud)
并且在运行时,它抛出了无法确定URI的错误.URI是Intranet的标识符吗?你确定这不是银光吗?我正在做一个WPF应用程序
你好伙计们我正在尝试获取一个图像(来自资源的帧)将其覆盖在原始位图上.到目前为止,我无法使我的Bitmap进入框架,因为框架始终为空.原始位图现在显示在框架内.这是我用来完成这个的代码.
Run Code Online (Sandbox Code Playgroud)Canvas canvas = new Canvas(); Bitmap border = null; Bitmap scaledBorder = null; border = BitmapFactory.decodeResource(getResources(), R.drawable.frame1); int width = bmp.getWidth(); int height = bmp.getHeight(); scaledBorder = Bitmap.createScaledBitmap(border,width,height, false); canvas.drawBitmap(scaledBorder, 0, 0, new Paint()); view.setImageBitmap(scaledBorder);
bmp作为我在Gallery或Camera中的原始位图.我找不到把它们放在一起.只显示帧而不是bmp.提前致谢.
我正在制作一个Android应用程序,我使用它来缩放位图
bitmap2 = Bitmap.createScaledBitmap(bmp, 150, 150, true);
这个图像在大屏幕的手机上看起来不错......但是当它在小尺寸的手机上使用时它会不成比例.....任何人都知道它的解决方案吗?
我试图在C#中声明并初始化一个位图,但似乎找不到该库.它只是告诉我创建Bitmap类.即使using System.Drawing手动添加" "也没有效果.
using System.Drawing
...
Bitmap img = new Bitmap(500, 500);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我使用的是.NET Framework 4.5,据微软称:
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0
Run Code Online (Sandbox Code Playgroud)
如果不推荐使用,我如何使用.Net Framework 4.5在C#中创建位图?
为什么在此示例中未触发 ImageOpened 事件?我在 Win8 的 WinRT 应用程序中使用它。
BitmapImage myImage = new BitmapImage();
myImage.ImageOpened += myImage_ImageOpened;
myImage.UriSource = new Uri("ms-appx:/Assets/Image.png");
private void myImage_ImageOpened(object sender, RoutedEventArgs e)
{
int pixelHeight = (sender as BitmapImage).PixelHeight;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是 ImageOpened 事件没有被触发。我想检查图像的 PixelHeight 和 PixelWidth,但如果没有收到此事件,则无法检查。
您好,我正在开发一个程序,将 640x480 位图图像缩小为 320x240 图像。我已经研究这个问题有一段时间了,但我发现的所有好的例子都是为了增加图像的大小。
(参见此处:http://cboard.cprogramming.com/c-programming/154737-help-program-resize-image.html)
我很难将该计划中所做的事情转化为我需要完成的事情。到目前为止,这是我的代码:
include stdio.h
include stdlib.h
include string.h
include math.h
pragma pack(push, 1)
typedef struct tagBITMAPFILEHEADER
{
unsigned short bfType; //specifies the file type
unsigned int bfSize; //specifies the size in bytes of the bitmap file
unsigned short bfReserved1; //reserved; must be 0
unsigned short bfReserved2; //reserved; must be 0
unsigned int bfOffBits; //species the offset in bytes from the bitmapfileheader to the bitmap bits
} BITMAPFILEHEADER;
pragma pack(pop)
pragma pack(push, 1)
typedef …Run Code Online (Sandbox Code Playgroud) 我正在使用MVVM在Windows 10上实现通用Windows应用程序.我有一个文件选择器,允许我选择一个图像.该图像显示在图像控件中.Image Control的源绑定到视图模型中的属性.此属性是一个字节数组.我需要一个转换器来转换字节数组中的BitmapImage.我已经阅读了很多东西,但找不到合适的东西.我在https://writeablebitmapex.codeplex.com/上找到了有趣的东西 但是如果我想使用这个包我需要一个WriteableBitmap而不是BitmapImage.预先感谢您的帮助.
我有以下代码可以上传图像并使用 System.Drawing.Graphics 以 150 x 200 div 的大小绘制它,但是当图像是从 IOS 设备获取时,图片会向右旋转 90 度。
仅供参考:我在 JavaScript 画布中绘制图像时遇到了同样的问题,这个解决方案对我有用。因此我在 C# 中寻找等效的解决方案
private System.Drawing.Image ResizeAndDraw(System.Drawing.Image objTempImage)
{
Size objSize = new Size(150, 200);
Bitmap objBmp;
objBmp = new Bitmap(objSize.Width, objSize.Height);
Graphics g = Graphics.FromImage(objBmp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
//Rectangle rect = new Rectangle(x, y, thumbSize.Width, thumbSize.Height);
Rectangle rect = new Rectangle(0,0,150,200);
//g.DrawImage(objTempImage, rect, 0, 0, objTempImage.Width, objTempImage.Height, GraphicsUnit.Pixel);
g.DrawImage(objTempImage, rect);
return objBmp;
}
Run Code Online (Sandbox Code Playgroud) private void SetAlpha(string location)
{
//bmp is a bitmap source that I load from an image
bmp = new BitmapImage(new Uri(location));
int[] pixels = new int[(int)bmp.Width * (int)bmp.Height];
//still not sure what 'stride' is. Got this part from a tutorial
int stride = (bmp.PixelWidth * bmp.Format.BitsPerPixel + 7)/8;
bmp.CopyPixels(pixels, stride, 0);
int oldColor = pixels[0];
int red = 255;
int green = 255;
int blue = 255;
int alpha = 0;
int color = (alpha << 24) + (red << …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我创建了一个类SerializableBitmapImage,它显示默认图像,而另一个图像从Internet下载.它还允许将下载的图像序列化为字节数组,因此不需要在每次应用程序启动时下载图像.我目前在"Card"类中有一个SerializableBitmapImage,它在卡数据完成下载时保存:
var resp = await AppData.API.GetCards();
if (resp != null)
{
if (AppData.CardsData == null)
AppData.CardsData = new CardsData();
AppData.CardsData.Update(resp);
AppData.SaveCards();
FillCards();
}
Run Code Online (Sandbox Code Playgroud)
但是,有时SerializableBitmapImage中的图像在调用AppData.SaveCards()时没有完成下载,导致图像无法保存.所以,我正在寻找一种延迟保存的方法,直到下载图像为止.现在,我在SerializableBitmapImage的构造函数中下载图像,如下所示:
Image = new BitmapImage(defaultUri); //set to default while downloading
BitmapImage img = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
img.ImageOpened += (sender, e) => //download successful, set Image to downloaded image
{
Image = sender as BitmapImage;
NotifyPropertyChanged("Image");
};
img.UriSource = downloadUri; //download the image
Run Code Online (Sandbox Code Playgroud)
我在SerializableBitmapImage中创建了一个Task来等待图像完成,但我不确定它是否以健康的方式完成它的工作.
public async Task WaitForImageDownload()
{
while (Image == null || …Run Code Online (Sandbox Code Playgroud)