你应该怎么处理BitmapSource?
// this wont work because BitmapSource doesnt implement IDisposable
using(BitmapSource bitmap = new BitmapImage(new Uri("myimage.png")))
{
}
Run Code Online (Sandbox Code Playgroud) 我在picturebox中有一个图像.我想将该图像作为位图.
我的一行代码是:
Bitmap default_image = (Bitmap)pictureBox5.Image.Clone();
但我得到的是:
default_image value=null;
谁能帮我.
我正在开发一个Windows Phone应用程序,可以通过MediaPlayer API从音乐文件动态读取相册艺术.我希望获得专辑艺术并调整视图的背景.由于调整大小会丢失细节并使图像变得难看,所以我想模糊它或某种效果.有没有我可以模糊图像的API?(来自C#还是XAML)?非常感谢!
我找到了这个链接,说明我如何在我的身上发光效果ImageButton.因此,只要用户按下ImageButton该onTouchEvent()功能被称为有我所说的setImageBitmap()功能.问题是这个函数(setImageBitmap())似乎根本没有效果.
什么有效:
1)到目前为止,我扩展ImageButton如下
// Pen.java
public class Pen extends ImageButton {
public Pen(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
System.out.println("Now I am setting Pen");
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在Activity I中创建Pen(自定义ImageButton)实例,从实例定义setGlow()和调用.setImageBitmap()Pen
//MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Pen myImgbutton;
myImgbutton = (Pen) findViewById(R.id.pen); …Run Code Online (Sandbox Code Playgroud) 我使用核心WIN32和VC++创建了一个Windows应用程序.在我的父窗口中,我有一个子窗口和两个按钮"保存"和"发送".
当用户单击"保存"按钮时,我想要savefileDialog打开,用户应该能够将图像保存为位图文件.
应该使用WinSock API将相同的文件发送给远程用户....我的问题是,我不知道如何将窗口的屏幕截图保存到位图文件中...
请帮帮我...我没有使用MFC,ATL或WTL ....
提前致谢,
我需要动态加载许多(有时数百个)缩略图.出于性能原因,我需要在有限数量的请求中执行此操作,我使用单个请求/响应进行测试.我正在为响应中的图像发送二进制数据,并使用MemoryStream将它们加载到BitmapImage中.这工作正常,直到我加载超过约80个缩略图,然后我得到灾难性失败例外.为了确保我的数据没有损坏,我尝试使用相同的字节数组多次加载BitmapImage,并在80次左右加载后崩溃.
下面是从字节数组加载图像的示例,已知字节数组具有有效的图像数据(png):
private BitmapImage LoadImage(byte[] imageData)
{
BitmapImage img = new BitmapImage();
MemoryStream stream = new MemoryStream(imageData);
img.SetSource(stream); // Exception thrown here after too many images loaded.
return img;
}
Run Code Online (Sandbox Code Playgroud)
然后我使用BitmapImage作为页面上Image元素的源,但错误发生在img.SetSource(...)上面的行中.
添加GC.Collect()到我正在加载缩略图图像的循环允许我加载更多图像,所以我认为这与内存管理有关,但我不知道我能做些什么来解决问题.
我有一个应用程序(WPF),它创建了大量的BitmapImages(如25000).似乎框架使用了一些内部逻辑,因此在创建之后大约消耗300 MB的内存(150个虚拟内存和150个物理内存).这些BitmapImages将添加到Image对象中,并将它们添加到Canvas中.问题是,当我释放所有那些图像时,内存不会被释放.我怎样才能释放记忆?
应用程序很简单:Xaml
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Canvas x:Name="canvas" Grid.ColumnSpan="2"></Canvas>
<Button Content="Add" Grid.Row="1" Click="Button_Click"/>
<Button Content="Remove" Grid.Row="1" Grid.Column="1" Click="Remove_click"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
代码隐藏
const int size = 25000;
BitmapImage[] bimages = new BitmapImage[size];
private void Button_Click(object sender, RoutedEventArgs e)
{
var paths = Directory.GetFiles(@"C:\Images", "*.jpg");
for (int i = 0; i < size; i++)
{
bimages[i] = new BitmapImage(new Uri(paths[i % paths.Length]));
var image = new Image();
image.Source = bimages[i];
canvas.Children.Add(image);
Canvas.SetLeft(image, i*10);
Canvas.SetTop(image, i …Run Code Online (Sandbox Code Playgroud) 如何在WPF中将WriteableBitmap对象转换为对象BitmapImage?
这个链接涵盖了silverlight,WPF中的进程不一样,WriteableBitmap对象没有SaveJpeg方法.
所以我的问题是如何在WPF中将WriteableBitmap对象转换为对象BitmapImage?
我正在尝试做一个非常简单的事情:获取图像的大小.
所以我创建了我,BitmapImage但是当我尝试访问PixelWidth和时,我得到0 PixelHeight.
我怎么能做到这一点呢?
编辑:(添加示例代码)
我只是这样做:
var baseUri = new Uri("ms-appx:///");
var bitmapImage = new BitmapImage(new Uri(baseUri, "Assets/Logo.png"));
MyImage.Source = bitmapImage;
Debug.WriteLine("Width: " + bitmapImage.PixelWidth + " Height: " + bitmapImage.PixelHeight);
Run Code Online (Sandbox Code Playgroud)
在控制台中,我得到:
Width: 0 Height: 0
Run Code Online (Sandbox Code Playgroud) 我最近从ImageView扩展到创建一个CircularImageView类,它使图像呈圆形,带有彩色边框.这是通过onDraw(canvas)方法绘制到传入的画布上完成的:
//load the bitmap
loadBitmap();
// init shader
if(image !=null)
{
shader = new BitmapShader(Bitmap.createScaledBitmap(image, viewWidth + (borderWidth * 2), viewHeight + (borderWidth * 2), true), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
int circleCenter = viewWidth / 2;
// circleCenter is the x or y of the view's center
// radius is the radius in pixels of the cirle to be drawn
// paint contains the shader that will texture the shape
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth, paintBorder);
canvas.drawCircle(circleCenter …Run Code Online (Sandbox Code Playgroud) bitmapimage ×10
c# ×4
wpf ×3
.net ×2
android ×2
bitmap ×2
image ×2
.net-3.5 ×1
c++ ×1
effect ×1
picasso ×1
picturebox ×1
silverlight ×1
visual-c++ ×1
winapi ×1
winrt-xaml ×1