![](/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.