![](/img/trans.png)
[英]How can I open an image and edit the image with C# .Net Compact Framework.
[英]How do I create a thumbnail from an image using C# Win Mobile 6.5/Compact framework?
我正在尝试制作/使用比相机拍摄的图像小的图像来显示程序的某些部分(由于内存问题...)
不幸的是,我似乎无法找到在移动设备上制作较小图像/缩略图的方法-在普通窗口中可能的方法...
有没有办法在Win Mobile 6.5 / Compact Framework上制作较小的图像?
例如-这些在Win Mobile上不起作用
这看起来很有希望 -但我只想将图像放在PictureBox上-不确定如何使用它来使其工作。
此代码应该是可行的。 我也实现了此代码。 为此,我使用了OpenNETCF.Drawing.dll。
barray = GetImage(filepath);
if (barray != null)
{
ms.Write(barray, 0, barray.Length - 1);
imageBitmap = CreateThumbnail(ms, new Size(PreviewImageWidth, PreviewImageHeight));
bm = ImageUtils.IBitmapImageToBitmap(imageBitmap);
// m_CurrentImageID = Convert.ToInt32(lstPic.ToList()[index].Id);
PictureBox ib = ((PictureBox)this.imagePanel.Controls[(nIndex * 2) + 1]);
ib.Image = bm;
}
private byte[] GetImage(string FilePath)
{
byte[] barray;
if (File.Exists(FilePath))
{
FileInfo _fileInfo = new FileInfo(FilePath);
long _NumBytes = _fileInfo.Length;
FileStream _FStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
BinaryReader _BinaryReader = new BinaryReader(_FStream);
barray = _BinaryReader.ReadBytes(Convert.ToInt32(_NumBytes));
_FStream.Flush();
_FStream.Dispose();
return barray;
}
else
{
return null;
}
}
public IBitmapImage CreateThumbnail(Stream stream, Size size)
{
IBitmapImage imageBitmap;
ImageInfo ii;
IImage image;
ImagingFactory factory = new ImagingFactoryClass();
try
{
factory.CreateImageFromStream(new StreamOnFile(stream), out image);
image.GetImageInfo(out ii);
factory.CreateBitmapFromImage(image, (uint)size.Width, (uint)size.Height, ii.PixelFormat, InterpolationHint.InterpolationHintDefault, out imageBitmap);
return imageBitmap;
}
catch (Exception ex)
{
CreateLogFiles Err = new CreateLogFiles();
Err.ErrorLog(ex.Message);
return null;
}
finally
{
imageBitmap = null;
image = null;
factory = null;
}
}
这应该工作:
this.pictureBox1.Image = System.Drawing.Image.FromFile(@"\path to image").GetThumbnailImage(100, 100, null, IntPtr.Zero);
但是缩图的质量可能不那么好。 对于高质量的缩略图,您可以在这里参考这篇文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.