没有.net库的图像裁剪C# [英] Image cropping C# without .net library

查看:56
本文介绍了没有.net库的图像裁剪C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议如何裁剪图像(例如jpeg),而不使用任何.NET框架结构,而仅使用原始字节吗?由于这是Silverlight中唯一的方式...

Can anyone advise on how to crop an image, let's say jpeg, without using any .NET framework constructs, just raw bytes? Since this is the only* way in Silverlight...

还是指向图书馆?

我不关心渲染,我不想在上传之前操纵jpg.

I'm not concerned with rendering i'm wanting to manipulate a jpg before uploading.

* Silverlight中没有可用的GDI +(System.Drawing)或WPF(System.Windows.Media.Imaging)库.

*There are no GDI+(System.Drawing) or WPF(System.Windows.Media.Imaging) libraries available in Silverlight.

锁定位需要GDI +,已澄清问题

Lockbits requires GDI+, clarified question

使用fjcore: http://code.google.com/p/fjcore/调整大小,但无法裁剪:(

Using fjcore: http://code.google.com/p/fjcore/ to resize but no way to crop :(

推荐答案

您可以轻松地在fjcore中编写自己的作物.从Resizer的代码开始

You could easily write crop yourself in fjcore. Start with the code for Resizer

http://web.archive.org/web/20140304090029/http://code.google.com:80/p/fjcore/source/browse/trunk/FJCore/Resize/ImageResizer.cs ?

和FilterNNResize-您可以看到图像数据的存储方式-它只是像素的简单数组.

and FilterNNResize -- you can see how the image data is stored -- it's just simple arrays of pixels.

重要的部分是:

for (int y = 0; y < _newHeight; y++)
{
    i_sY = (int)sY; sX = 0;

    UpdateProgress((double)y / _newHeight);

    for (int x = 0; x < _newWidth; x++)
    {
        i_sX = (int)sX;

        _destinationData[0][x, y] = _sourceData[0][i_sX, i_sY];

        if (_color) {

            _destinationData[1][x, y] = _sourceData[1][i_sX, i_sY];
            _destinationData[2][x, y] = _sourceData[2][i_sX, i_sY];
        }

        sX += xStep;
    }
    sY += yStep;
}

向您显示数据存储在一个彩色平面数组中(1个元素用于8bpp灰色,3个元素用于颜色),并且每个元素都有一个图像的二维字节数组(x,y).

shows you that the data is stored in an array of color planes (1 element for 8bpp gray, 3 elements for color) and each element has a 2-D array of bytes (x, y) for the image.

您只需要遍历目标像素,然后从源中的适当位置进行复制.

You just need to loop through the destination pixels, copying then from the appropriate place in the source.

别忘了向fjcore的作者提供补丁

edit: don't forget to provide the patch to the author of fjcore

这篇关于没有.net库的图像裁剪C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆