/// <summary> /// 获取歌曲中前1Mbt中包含的图片,并返回 /// </summary> public BitmapImage GetJPGFromStream(SongInfo songInfo, int PixelWidth = 0, int PixelHeight = 0) { MemoryStream ms = null; try { BitmapImage image = new BitmapImage(); byte[] buffer = GetJPGBuffer(songInfo, 10240); if (buffer != null) { ms = new MemoryStream(buffer); } image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.StreamSource = ms; try { try { image.EndInit(); } catch (NotSupportedException) { MemoryStream saveStream = new MemoryStream(); if (!BasicMethodClass.MakeThumbnail(ms, saveStream, 602, 602, "W", "jpg")) { return(null); } saveStream.Seek(0, SeekOrigin.Begin); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.StreamSource = saveStream; image.EndInit(); saveStream.Dispose(); } } catch (Exception) { return(null); } if (PixelWidth != 0) { image.DecodePixelWidth = PixelWidth; } if (PixelHeight != 0) { image.DecodePixelHeight = PixelHeight; } return(image); } catch { return(null); } finally { if (ms != null) { ms.Dispose(); } } }
/// <summary> /// 获取显著图片 /// </summary> /// <param name="filepath">图片文件流</param> /// <param name="prewidth">预处理后的宽</param> /// <param name="preheight">预处理后的高</param> /// <param name="premode">预处理时的压缩方式</param> /// <param name="pretype">预处理图片后的类型</param> /// <param name="R">最终切割大小</param> /// <param name="Tolerance">切割阙值(切图时判断是否连续的亮度边界,越大越严格)</param> /// <returns></returns> public Bitmap GetSRDFromStream(Stream InImageStream, double prewidth, double preheight, string premode, string pretype, Rectangle R, int Tolerance = 200) { if (R == null) { R = new System.Drawing.Rectangle(0, 0, 256, 256); } MemoryStream ms_out = new MemoryStream(); Bitmap Srcbitmap = new Bitmap(InImageStream); //压缩尺寸以加快速度 BasicMethodClass.MakeThumbnail(Srcbitmap, ms_out, Math.Min(prewidth, Srcbitmap.Width), Math.Min(preheight, Srcbitmap.Height), premode, pretype); if (InImageStream == null) { throw new Exception("not expectation result"); } if (ms_out == null) { return(null); } var vdcSrcBitmap = new Bitmap(ms_out); ms_out.Dispose(); var vdcmap = VisualAttentionDetectionClass.SalientRegionDetectionBasedOnFT(vdcSrcBitmap); if (R.Width > Srcbitmap.Width || R.Height > Srcbitmap.Height) {//格式化输出图片尺寸 ms_out = new MemoryStream(); BasicMethodClass.MakeThumbnail(Srcbitmap, ms_out, R.Width, R.Height, premode, pretype); Srcbitmap.Dispose(); Srcbitmap = new Bitmap(ms_out); ms_out.Dispose(); } CutImageClass cuter = new CutImageClass(vdcmap, R, Tolerance); var GenerImage = cuter.GCSsimp_getLightPointFromSource(Srcbitmap); vdcSrcBitmap.Dispose(); vdcmap.Dispose(); Srcbitmap.Dispose(); return(GenerImage); }
/// <summary> /// 获取主色调 /// </summary> /// <param name="bitmap"></param> /// <returns></returns> public static Color GetMajorColor(Bitmap bitmap) { Rectangle R; R = new System.Drawing.Rectangle(0, 0, 256, 256); MemoryStream ms_out = new MemoryStream(); BasicMethodClass.MakeThumbnail(bitmap, ms_out, 600, 200, "W", "jpg"); var srcBitmap = new Bitmap(ms_out); //var DH = new DominantHue(srcBitmap).GetDominantHue(0.5, 0.65, 210); var DH = new DominantHue(srcBitmap).GetDominantHue(0.4, 0.55, 50); ms_out.Dispose(); srcBitmap.Dispose(); return(DH); }
public static CutImageClass MakeThumbnail(this CutImageClass cutImageClass, int width, int height, string mode = "W") { if (cutImageClass.CurDestBitmap == null) { cutImageClass.CurDestBitmap = BasicMethodClass .MakeThumbnail(cutImageClass.srcBitmap, width, height, mode, "jpg"); } else { cutImageClass.CurDestBitmap = BasicMethodClass .MakeThumbnail(cutImageClass.CurDestBitmap, width, height, mode, "jpg"); } cutImageClass.curDestImageWidth = cutImageClass.CurDestBitmap.Width; cutImageClass.curDestImageHeight = cutImageClass.CurDestBitmap.Height; //mss.Dispose(); return(cutImageClass); }