我尝试制作一个应用程序,允许用户从图库/拍照中选择图像,并将结果设置为位图.当我测试应用程序时,我发现三星设备的轮换是错误的.
搜索了一段时间后,我发现旋转不是谷歌定义的,但制造商本身和三星似乎有一些不同的设置.此外,还有一些建议使用另一种方法来检查旋转.
如何解决问题?(注意:不仅拍摄照片,而且画廊中的图片也有相同的旋转问题)
以下是从提供的文件路径获取getbitmap的代码:
private Bitmap getBitmap(String path) {
Uri uri = getImageUri(path);
InputStream in = null;
try {
in = mContentResolver.openInputStream(uri);
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, o);
in.close();
int scale = 1;
if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
scale = (int) Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
in = mContentResolver.openInputStream(uri);
Bitmap b = BitmapFactory.decodeStream(in, null, o2); …Run Code Online (Sandbox Code Playgroud) 我试图以最快的方式以编程方式降低图像的质量.现在,我能够读取图像byte[],然后作为一个MemoryStream读它Bitmap,并通过Drawing.Imaging.Encoder.Quality保存在需要时改变其质量20L.
我想知道是否有办法在不保存整个图像的情况下执行此操作.有没有办法只更改位图bmp1,或创建一个会降低图像质量的新位图?
byte[] imageBytes = convertImageToByteArray(bmpScreenshot);
MemoryStream mem = new MemoryStream(imageBytes);
using (Bitmap bmp1 = (Bitmap)Image.FromStream(mem))
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
ImageCodecInfo jgpEncoder = codecs[1];
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Quality;
myEncoderParameter = new EncoderParameter(myEncoder, 20L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"C:\TestPhotoQuality20L.jpg", jgpEncoder, myEncoderParameters);
}
Run Code Online (Sandbox Code Playgroud) 我需要一些帮助.
我将一个位图导入我的Win32窗口.我正在构建它,几秒钟后它开始滞后很多.我不知道为什么,但我想我使用它后没有正确地从内存中删除它.
提前感谢您的帮助.
我在测试时看到了一种行为.如果我没有移动窗口而不是移动窗口,但移动它后它开始滞后并阻止我的IDE.也许是WM_PAINT的东西?这是我的代码.
#include <windows.h>
//For more makros
#include <windowsx.h>
#include "Simulatron.h"
HINSTANCE hProgramInstance;
Simulatron Exo;
char Simulatron::m_szClassName[] = "Simulatron";
Simulatron::Simulatron(HINSTANCE hInstance)
{
m_hInstance = hInstance; // Save Instance handle
m_wndClass.cbSize = sizeof(WNDCLASSEX); // Must always be sizeof(WNDCLASSEX)
m_wndClass.style = CS_DBLCLKS; // Class styles
m_wndClass.lpfnWndProc = MainWndProc; // Pointer to callback procedure
m_wndClass.cbClsExtra = 0; // Extra bytes to allocate following the wndclassex structure
m_wndClass.cbWndExtra = 0; // Extra bytes to allocate following an instance of the structure
m_wndClass.hInstance …Run Code Online (Sandbox Code Playgroud) 我正在尝试模糊我的图像,并使用RenderScript在RelativeLayout的背景上显示模糊,应用程序在模拟器中工作,但手机中的应用程序不断崩溃,出现此错误:
08-05 22:21:36.543:E/RenderScript_jni(11549):无GC方法08-05 22:21:36.553:D/dalvikvm(11549):在/system/lib/libRSSupport.so 0x41803ab8中找不到JNI_OnLoad,跳过init 08-05 22:21:36.557:E/dalvikvm(11549):错误:找不到本地方法08-05 22:21:36.557:E/dalvikvm(11549):请求:Landroid/support/v8/renderscript /RenderScript; ._nInit :() V 08-05 22:21:36.558:E/JNIHelp(11549):RegisterNatives因'android/support/v8/renderscript/RenderScript'失败,中止08-05 22:21:36.558: A/libc(11549):0xdeadbaad(代码= 1),线程11549(m.example.login)的致命信号11(SIGSEGV)
这是我在单独的类上的模糊代码:
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v8.renderscript.*;
public class Blur {
public static Bitmap blurBitmap(Context context, Bitmap src) {
Bitmap outBitmap = src.copy(src.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, src);
final Allocation output = Allocation.createFromBitmap(rs, outBitmap);
final ScriptIntrinsicBlur script =
ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(25f);
script.setInput(input);
script.forEach(output);
output.copyTo(outBitmap);
rs.destroy();
return outBitmap;
}
}
Run Code Online (Sandbox Code Playgroud)
这里是MainActivity中的ny代码(我从图库中获取位图):
Uri selectedImageUri = data.getData();
Blur blur …Run Code Online (Sandbox Code Playgroud) 我在Android上通过Renderscript制作了3种模糊的位图.使用app很多次后,它会自动关闭.记录如下:
V/RenderScript(4548):用户支持的分配失败了步幅要求,回退到单独的分配
D/dalvikvm(4548):GC_EXPLICIT释放1K,5%释放21256K/22352K,暂停1ms + 4ms,总共20ms
在清单文件中启用了largeHeap,但它没有帮助.我需要通过renderscript在GPU中清除内存不是吗?我没有找到如何做到这一点.
Android操作系统:4.4.2,设备:Samsung Note II.
有谁知道如何处理这个?
我在Windows中编写类似于"Paint"的程序.起初我尝试制作一个"铅笔"函数来处理WM_MOUSEMOVE消息并正确调用SetPixel().但是当鼠标移动太快时,并非所有像素都出现(它们看起来像稀疏).我想我必须用另一个代码替换那个SetPixel()函数,但我不知道是什么.
我有两个包含工作日"位图"的字符串:例如,1------仅周一,--3-5--周三和周五,你明白了.
我想将这些与逻辑OR的等价物合并在一起,例如.1------|| --3-5--= 1-3-5--.最恐怖的方法是什么?我现在正在这样做,但感觉不是特别优雅:
week1, week2, merged = '1------', '--3-5--', ''
for i in range(0, len(week1)):
merged += week1[i] if week1[i] != '-' else week2[i]
print merged
Run Code Online (Sandbox Code Playgroud)
请注意,我使用的是Python 2.7,因此没有可变字符串,并且可以安全地假设输入字符串始终是正确格式化的(=始终-用于false并且1..7在正确的位置用于true).
我正在使用Picasso库在ViewPager中加载和显示图像.正在加载的图像具有高分辨率,我想为它们添加一个非采样大小.但是,我不知道应该如何或在何处添加此采样大小属性.我的ViewPagerAdapter.java类具有以下内容.
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView iv_page_image;
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.viewpager_item, container,false);
iv_page_image = (ImageView) itemView.findViewById(R.id.iv_page_image);
String path = pageList.get(position).getPageImage();
path = path.replaceAll(" ", "%20");
if (path != null && !(path.equalsIgnoreCase(""))) {
Picasso.with(mContext).load(path)
.placeholder(R.drawable.placeholder_empty)
.into(iv_page_image, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
}
});
}
((ViewPager) container).addView(itemView);
return itemView;
}
Run Code Online (Sandbox Code Playgroud)
我想在图片中添加如下内容
private static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
final int height …Run Code Online (Sandbox Code Playgroud) 所以我使用Recycler视图在网格中显示图像,并使用volley库从url下载图像作为位图.
public void onBindViewHolder(final TrendingAdapter.ViewHolder viewHolder, int i) {
ImageRequest request = new ImageRequest(url, new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
if (bitmap != null) {
viewHolder.getmImageView().setImageBitmap(bitmap);
}
}
}, 0, 0, null,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
AppController.getInstance().addToRequestQueue(request);
}
Run Code Online (Sandbox Code Playgroud)
问题是当我在下载图像之前滚动并跳过一个或多个视图并且该视图被回收时,图像donwnload reqest在这些中间视图上没有被取消,导致在实际图像之前闪现那些/那些图像加载在该视图中.
所以我想用标签取消那些中间图像请求,但无法弄清楚如何在其他并行视图中取消请求!
此外,当我使用凌空NetworkImageView(它自己这样的图像取消)给出了完美的结果.但我需要获取每个图像的位图来从中选择颜色,所以我不能使用NetworkImageView.
问)如何在使用recyclerview充气的特定imageview上取消所有待处理的凌空图像请求(除了它应该加载并且不影响其他平行视图的那个)?
android bitmap android-volley android-viewholder android-recyclerview
所以我目前正在开发一个工作/工作得非常好的图像缩放器,但是当我一次处理太多图像时崩溃程序时它给了我一个OutOfMemoryException.
所以为了解决这个问题,我已经将方法包装在using语句中,这样可以正确处理Bitmaps.
但是我注意到如果我在using语句中返回我的Bitmap,我得到这个"ArgumentException未处理"消息
这是我的ImageResize方法:
public Bitmap ResizeImage(MemoryStream ms, Size size)
{
if (comboBox2.Text == "Pixel")
{
using (Bitmap img = new Bitmap(new Bitmap(ms, true), size.Width, size.Height))
{
var original = new Bitmap(ms, true);
Graphics graphic = Graphics.FromImage(img);
//IRRELEVANT CODE.....
return img;
}
}
else
{
return null;
}
Run Code Online (Sandbox Code Playgroud)
在这里,当我尝试将图像保存在ImageResize方法之外时:
private void button1_Click(object sender, EventArgs e)
{
//IRRELEVANT CODE ...
img = ResizeImage(memory, new Size(getX(), getY()));
//IRRELEVANT CODE ...
img.Save(outputFileName, codec, encoderParams); //<-Exception occurs here
}
Run Code Online (Sandbox Code Playgroud)
当我删除using语句时,一切都工作得很好,但是我必须使用using块来处理Bitmap,以防止内存泄漏.此外,当我将图像保存在using语句中时,它也可以正常工作,但在我的情况下,这不是解决方案.
我究竟做错了什么?对我来说,似乎没有正确返回Bitmap.
我感谢任何帮助,并提前感谢Ravand