我正在尝试执行以下代码:
private void crop(HttpServletRequest request, HttpServletResponse response){
int x = 100;
int y = 100;
int w = 3264;
int h = 2448;
String path = "D:images\\upload_final\\030311175258.jpg";
BufferedImage image = ImageIO.read(new File(path));
BufferedImage out = image.getSubimage(x, y, w, h);
ImageIO.write(out, "jpg", new File(path));
}
Run Code Online (Sandbox Code Playgroud)
但一直给我同样的错误:
java.awt.image.RasterFormatException: (x + width) is outside of Raster
sun.awt.image.ByteInterleavedRaster.createWritableChild(ByteInterleavedRaster.java:1230)
java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1156)
Run Code Online (Sandbox Code Playgroud)
我的错误在哪里?
我正在寻找像ImageView.ScaleType中的CENTER_CROP
均匀缩放图像(保持图像的纵横比),使图像的尺寸(宽度和高度)等于或大于视图的相应尺寸(减去填充).然后图像在视图中居中.从XML,使用以下语法:android:scaleType ="centerCrop"
但对于VideoView.有这样的事吗?
请考虑以下示例:

源图像由6个区域组成,需要切成6个单独的图像.
如何使用imagemagick获得所需的输出.我试图理解imagemagick 示例中提供的可能解决方案,但未能将其转移到我的具体问题.
什么是一种解决这个问题的方法,最好是在一个班轮?由于我想要切片的所有区域都具有相同的大小,但只有它们的偏移量不同,有没有办法以某种方式传递预设的区域大小,然后简单地为每个区域添加xy-offset?
如何在中心裁剪图像?因为我知道盒子是一个定义左,上,右和下像素坐标的4元组,但我不知道如何获得这些坐标,所以它在中心作物.
We record a video of the user's face, and usually the face is located at the upper half of the video.
Later we wish to view the video, but the aspect ratio of the PlayerView might be different than the one of the video, so there needs to be some scaling and cropping.
我发现缩放PlayerView它的唯一方法是将它显示在它所拥有的整个空间中,但保持纵横比(当然需要在需要时进行裁剪),是通过使用app:resize_mode="zoom".以下是中心裁剪的示例:http://s000.tinyupload.com/?file_id = 00574047057406286563.显示内容的视图具有相似的宽高比越多,所需的裁剪越少.
但这仅适用于中心,这意味着它需要0.5x0.5的视频点,并从那一点开始进行缩放.这导致许多丢失视频重要内容的情况.
例如,如果我们有一个以纵向拍摄的视频,并且我们有一个方形的PlayerView并想要显示顶部区域,那么这将是可见的部分:
当然,如果内容本身是正方形,并且视图也是正方形,则应该显示整个内容,而不进行裁剪.
我试过通过Internet,StackOverflow(这里)和Github搜索,但我找不到怎么做.我发现的唯一线索是关于AspectRatioFrameLayout和AspectRatioTextureView,但我没有找到如何将它们用于此任务,如果它甚至可能的话.
我被告知(这里)我应该使用普通TextureView,并直接提供它 …
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
UIWebView *webView = (UIWebView*)aView;
NSString *heightStr = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
int height = [heightStr intValue];
// Get the number of pages needed to print. 9 * 72 = 648
int pages = ceil(height / 648.0);
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil );
CGRect frame = [webView frame];
for (int i = 0; i < pages; i++) {
// Check to …Run Code Online (Sandbox Code Playgroud) 我创建了一个逻辑,用于裁剪包含在网格内部边框内的图像.网格有很多边框,所以这个网格会有很多图片.问题是,当我缩放图片时,逻辑会缩放图片(这没关系)但是当我使用裁剪逻辑时,它AdornerLayer会像图片一样走出边框:
在这张图片上,pic没有缩放,所以这AdornerLayer是正确的:
我用来将裁剪添加到图像的代码:
private void AddCropToElement(FrameworkElement fel, System.Drawing.Image img)
{
if (!cropElements.ContainsKey(Convert.ToString(((Image)fel).Source)))
{
if (_felCur != null)
{
RemoveCropFromCur();
}
rcInterior = new Rect(
fel.ActualWidth * 0.2,
fel.ActualHeight * 0.2,
fel.ActualWidth * 0.6,
fel.ActualHeight * 0.6);
rectMoving = false;
Rect newRect = scaleRect(rcInterior, img);
imgCropMove = img;
AdornerLayer aly = AdornerLayer.GetAdornerLayer(fel);
_clp = new CroppingAdorner(fel, rcInterior);
aly.Add(_clp);
cropElements.Add(Convert.ToString(((Image)fel).Source), fel);
imageCropped = _clp.Crop(new System.Drawing.Bitmap(img), newRect);
_clp.CropChanged += HandleCropChanged;
_felCur = fel;
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,名为fel的对象是我要裁剪的图片,而Border是他的父级.
如果图像被缩放,我如何解决AdornerLayout外出的问题?
是否有一些客户端组件(jquery/swf)可以在浏览器中上传和裁剪(用户应该能够选择要裁剪的区域)图像,然后将裁剪后的图像发送到服务器?
我在asp.net-mvc上(不确定是否重要)
我只是想分享我写的这段代码.我尝试搜索自定义裁剪活动,但大多数都会导致默认的"com.android.camera.action.CROP",尽管问题是自定义裁剪或徒手裁剪活动.无论如何,我只是为自己制作了一个,希望它会帮助你们.
public class CropView extends ImageView {
Paint paint = new Paint();
private int initial_size = 300;
private static Point leftTop, rightBottom, center, previous;
private static final int DRAG= 0;
private static final int LEFT= 1;
private static final int TOP= 2;
private static final int RIGHT= 3;
private static final int BOTTOM= 4;
private int imageScaledWidth,imageScaledHeight;
// Adding parent class constructors
public CropView(Context context) {
super(context);
initCropView();
}
public CropView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
initCropView();
} …Run Code Online (Sandbox Code Playgroud) 我花了最后5个小时试图找到一种可行的方法来完成我认为非常简单的任务,如果它是我正在使用的.NET系列的早期版本:
我来到了几个处于预发布阶段或未完成阶段的图书馆.
有没有人完成上述任务而没有特别包括System.Drawing命名空间和/或为早期版本的.NET框架添加依赖项?
我最终使用System.Drawing非常烦人和令人失望的东西.如果您正在开发成千上万开发人员使用的软件,并且如果所有这些开发人员都依赖于该软件的组件,我相信,人们不能只想出一个新版本,在会议期间"甜言蜜语"展示它除了你的公开演讲技巧,而不是对你的工作嗤之以鼻,一方面自豪地高举它,另一方面,剥夺它最常用和要求的部分.
我非常兴奋地理解和欣赏 - 带有核心框架的.net的新时代 - 自从经典asp的第一天起成为一个忠诚的asp开发者 - 然而,对我来说,它只是一个不完整的产品,导致更多的挫折和失望而不是快乐.在当今内容驱动的世界中有数百万个网站,完全依赖内容管理,你不能只是说出来,"嘿,我有这种精彩,技术,更精简,更快的等等等等",但是错了,你会"管理"您的内容有一些问题..
不应该忘记,虽然,MS(和我们)对这个新的核心框架感到非常兴奋,现在是开源等,还有其他语言和框架在做MS正在做的事情,对于现在很长一段时间.
image-manipulation crop image-resizing asp.net-core-mvc asp.net-core