• 缩略图生成算法


    抄的,避免GetThumbNail GIF透明信息丢失的问题,
    private unsafe Bitmap GetThumbnail(Bitmap src, int width, int height)
                
    {
                    
    // preserve source-image aspect ratio 

                    
    float src_t = (float) src.Height/(float) src.Width;

                    
    if (src_t > ((float) height/(float) width))
                        width 
    = (int) (height/src_t);
                    
    else
                        height 
    = (int) (width*src_t);

                    
    // end of preserve source-image aspect ratio 


                    
    if (src.PixelFormat == PixelFormat.Format8bppIndexed)
                    
    {
                        
    // do it yourself 

                        Bitmap dst 
    = new Bitmap(width, height, src.PixelFormat);
                        dst.Palette 
    = src.Palette;

                        BitmapData dstbd 
    =
                            dst.LockBits
                                (
                                
    new Rectangle(00, dst.Width, dst.Height),
                                ImageLockMode.WriteOnly,
                                dst.PixelFormat
                                );
                        
    try
                        
    {
                            BitmapData srcbd 
    =
                                src.LockBits
                                    (
                                    
    new Rectangle(00, src.Width, src.Height),
                                    ImageLockMode.ReadOnly,
                                    src.PixelFormat
                                    );
                            
    try
                            
    {
                                
    byte* srcp;
                                
    byte* dstp;

                                
    float m = (float) src.Width/(float) dst.Width;


                                
    for (int r = 0; r < dst.Height; ++r)
                                
    {
                                    dstp 
    = (byte*) dstbd.Scan0;
                                    dstp 
    += dstbd.Stride*r;

                                    
    for (int c = 0; c < dst.Width; ++c)
                                    
    {
                                        srcp 
    = (byte*) srcbd.Scan0;
                                        srcp 
    += srcbd.Stride*(int) (r*m);
                                        srcp 
    += (int) (c*m);

                                        
    *dstp++ = *srcp;
                                    }

                                }


                            }

                            
    finally
                            
    {
                                src.UnlockBits(srcbd);
                            }

                        }

                        
    finally
                        
    {
                            dst.UnlockBits(dstbd);
                        }


                        
    return dst;
                    }

                    
    else
                    
    {
                        
    // rely on microsoft guy 

                        
    return (Bitmap) src.GetThumbnailImage(width, height, null, IntPtr.Zero);
                    }

                }
  • 相关阅读:
    015.Delphi插件之QPlugins,FMX插件窗口
    014.Delphi插件之QPlugins,MDI窗口
    013.Delphi插件之QPlugins,模块化代码示例
    012.Delphi插件之QPlugins,多实例内嵌窗口服务
    011.Delphi插件之QPlugins,延时加载服务
    010.Delphi插件之QPlugins,遍历服务接口
    009.Delphi插件之QPlugins,服务的热插拔
    008.Delphi插件之QPlugins,服务的两种调用方法
    007.Delphi插件之QPlugins,插件的卸载和重新加载
    006.Delphi插件之QPlugins,多服务演示
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/284719.html
Copyright © 2020-2023  润新知