假如有一图片,长100宽100  现要根据需要把这张图片均匀的分割成若干小块并分别保存,比如要分成10*10块,要达到这个目的如何实现呢?不论用什么方法都可以,能用DELPHI实现更好!有谁知道望告知!先谢过了!

解决方案 »

  1.   

    FT,我居然帮人写过一段需求完全一样的代码...不过...因为只是帮忙,比较偷懒,代码丑了点,效率也差了,凑和着看吧BOOL Bmp_Incise(const char *filename)
    {
            BITMAPFILEHEADER bmpfileheader;
            BITMAPINFOHEADER bmpinfoheader;
            ifstream bmpfile;
            bmpfile.open(filename, ios::in|ios::binary);
            if(!bmpfile) {
                    return false;
            }
            else {
                    bmpfile.read((char *)&bmpfileheader, sizeof(bmpfileheader));
                    if(bmpfileheader.bfType != 0x4D42) return false;
                    bmpfile.read((char *)&bmpinfoheader, sizeof(bmpinfoheader));
                    if(bmpinfoheader.biWidth == 0 || bmpinfoheader.biHeight == 0) return false;
                    if(bmpinfoheader.biWidth != 100 || bmpinfoheader.biHeight != 100) return false;
                    if(bmpinfoheader.biPlanes != 1) return false;
                    if(bmpinfoheader.biBitCount != 24 && bmpinfoheader.biBitCount != 32) return false;
                    if(bmpinfoheader.biCompression != 0) return false;
                    if(bmpinfoheader.biSizeImage % 4 != 0) return false;
            }
            ofstream outfile[10];
            int bit = bmpinfoheader.biBitCount / 8;
            char *buf = new char[100 * bit];
            for(int i=0; i<10; i++) {
                    char str[20];
                    for(int j=0; j<10; j++) {
                            sprintf(str, "%d", i * 10 + j + 1);
                            strcat(str, ".bmp\0");
                            outfile[j].open((char *)str, ios::out|ios::binary);
                            bmpinfoheader.biWidth = 10;
                            bmpinfoheader.biHeight = 10;
                            bmpinfoheader.biSizeImage = ((10 * bit - 1) / 4 + 1) * 4 * 10;
                            bmpfileheader.bfSize = bmpinfoheader.biSizeImage + sizeof(bmpfileheader) + sizeof(bmpinfoheader);
                            outfile[j].write((char *)&bmpfileheader, sizeof(bmpfileheader));
                            outfile[j].write((char *)&bmpinfoheader, sizeof(bmpinfoheader));
                    }
                    for(int j=0; j<10; j++) {
                            for(int k=0; k<10; k++) {
                                    bmpfile.read(buf, 10 * bit);
                                    outfile[k].write(buf, 10 * bit);
                                    if(bit = 3) {
                                            outfile[k].put(0);
                                            outfile[k].put(0);
                                    }
                            }
                    }
                    for(int j=0; j<10; j++) {
                            outfile[j].close();
                    }
            }
            delete[] buf;
            return true;
    }
      

  2.   

    用Rxlib组件里面的picclip就完全OK了
      

  3.   

    或者直接copyrect也行,很简单的啊:P