我有一个径向alpha渐变的png,因此在边缘处它的黑色和中心是完全透明的,具有漂亮的平滑渐变.
当我加载我的Bitmap并将其显示在SurfaceView Canvas上时,我会得到不好的alpha条带.而不是一个漂亮的平滑渐变,alpha值似乎跳下来并导致所有相同alpha值的大带.
据我所知,带有alpha通道的位图在加载或绘制时不应转换.如何在画布上正确绘制我的png?
任何帮助将不胜感激,谢谢!= d
我需要使用ndk在C++中创建Bitmaps并将它们传递给Java.我不是指复制,但实际上将它们作为参数传递或返回值或其他任何类似的东西,因为复制它们会太慢.我也真的需要在NDK部分而不是在java中创建它们.
有谁知道这样做的方法?
这是我的LayerList的简化版本.它在项目中有一个位图以防止缩放.我想以编程方式更改此位图的drawable.有没有办法做到这一点?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/item"
android:left="165dp"
android:top="245dp" >
<bitmap
android:id="@+id/bitmap"
android:src="@drawable/tag_de_01"
android:gravity="top|left" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我尝试了以下但没有成功:
Resources res = getResources();
LayerDrawable layerDrawable = (LayerDrawable) res.getDrawable(R.drawable.layer_list_drawable);
Drawable newDrawable = (Drawable)res.getDrawable(R.drawable.something);
// works, but scales the image because the drawable of the item is set instead the one of the bitmap
layerDrawable.setDrawableByLayerId(R.id.item, newDrawable);
// doesn't work at all
layerDrawable.setDrawableByLayerId(R.id.bitmap, newDrawable);
Run Code Online (Sandbox Code Playgroud) 我ViewFlow在我的应用程序中使用自己的Android实例.我正在从Web服务下载加密图像,而不是将它们保存在SD卡上.我正在使用viewflow来动态解密图像并显示它们.但问题是,当用户开始更快地更改图像时,它会给我一个OutOfMemoryException信息,而我发现/测试的所有信息对我的情况都不起作用.这是我正在使用的:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.image_item, null);
}
try {
File bufferFile = new File(ids.get(position));
FileInputStream fis = new FileInputStream(bufferFile);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keySpec = new SecretKeySpec("01234567890abcde".getBytes(), "AES");
IvParameterSpec ivSpec = new IvParameterSpec("fedcba9876543210".getBytes());
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
CipherInputStream cis = new CipherInputStream(fis, cipher);
BitmapFactory.Options o = new BitmapFactory.Options();
final int REQUIRED_SIZE=300*1024;
//Find the correct scale value. It should be the power of …Run Code Online (Sandbox Code Playgroud) 我试图从相机意图捕获图像,然后在其上应用图像过滤器.详细说明图像将是由相机捕获的图像,并且图像过滤器将作为png文件在资源中可用.我可以将滤镜叠加在原始图像的顶部.但是,一旦覆盖,原始图像"几乎"不可见(这意味着过滤器实际上堆叠在原始图像上而不仅仅是替换它).我有几张图片来说明我的问题.第一张图片是在Photoshop中 - 当我在图像上面放置一个滤镜时,它似乎很好.第二个图像是由下面引用的代码生成的 - 您可以清楚地看到滤镜效果丢失.有人会知道为什么会发生这样的事情.我在这里错过了一些逻辑吗?


以下是我的代码.如果您发现此处缺少任何最佳做法,我深表歉意.我最初尝试测试代码:
mPictureView = (ImageView) findViewById(R.id.pictureView);
filterButton = (Button) findViewById(R.id.filter_button1);
// define the threshold fro scaling the image
private final double SCALE_THRESHOLD = 6.0;
// acquire the bitmap (photo captured) from the Camera Intent - the uri is
// passed from a previous activity that accesses the camera and the current
// activity is used to display the bitmap
Uri imageUri = getIntent().getData();
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
// set the imageView in the current activity …Run Code Online (Sandbox Code Playgroud) 声明了一个位图
private Bitmap img1 = null;
private Bitmap img2 = null;
Run Code Online (Sandbox Code Playgroud)
从openFileDialog中选择后,图像将被推送.
选定的图像被放置在一个数组中.
imgName = openFD.FileNames;
Run Code Online (Sandbox Code Playgroud)
然后按钮1显示这些图像.
pictureBox1.Image = Image.FromFile(imgName[0]);
pictureBox2.Image = Image.FromFile(imgName[1]);
Run Code Online (Sandbox Code Playgroud)
我用这个替换了button1代码
img1 = Image.FromFile(imgName[0]);
img2 = Image.FromFile(imgName[1]);
Run Code Online (Sandbox Code Playgroud)
但是会发生错误
无法将类型'System.Drawing.Image'隐式转换为'System.Drawing.Bitmap'
我试着将代码更改为img1 = Bitmap.FromFile(imgName[0]);.但仍然有同样的错误.
有任何建议如何纠正或做到这一点?
我一直在创建一个绘图应用程序作为WPF的测试,并且一直进展顺利.我遇到的问题是,如果我每次移动时将鼠标下的像素绘制到位图,我每次更新只会获得一个像素.当鼠标快速移动时,它不会在其间绘制像素.我需要知道在WPF中使用的最佳方法是在像素之间画一条线WriteableBitmap
编辑:现在我有这个:

所以很久以前我在开发墙纸更换器,并将其发布。一段时间后,我开始收到评论,墙纸的尺寸无法正确调整。我也尝试了不同大小的emus,它们是正确的。我正确地缩放了位图,等等。但是,Android倾向于以某种方式重新缩放墙纸!有办法避免这种情况吗?我的代码:
Display display = parent.getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Bitmap scaled = Bitmap.createScaledBitmap(wallpaper, width, height, true);
WallpaperManager wm = WallpaperManager.getInstance(getContext());
wm.setBitmap(scaled);
Run Code Online (Sandbox Code Playgroud)
我也一直在尝试其他方法,但似乎无济于事,即使我事后检查重新缩放的墙纸是否正确大小也是如此。:(有什么想法吗?
我有一个带有轨迹栏滑块控件的工具,用于调整图像的亮度,对比度,伽玛等.
当用户拖动滑块时,我试图获取我的图像的实时更新.亮度和伽马算法是可接受的速度(大约170ms).但对比度算法约为380ms.
基本上我的表单是一个带滑块的工具窗口.每次更新图像时,它都会向父项发送一个重绘新图像的事件.工具窗口将原始未修改的图像锁定在内存中,因此我始终可以访问它的字节.因此,每次更改滑块的ValueChanged事件(例如"对比度"滑块)时,我都会这样做.
码:
double newValue = 0;
double c = (100.0 + contrast) / 100.0;
c *= c;
for (int i = 0; i < sourcePixels.Length; i++)
{
newValue = sourcePixels[i];
newValue /= 255.0;
newValue -= 0.5;
newValue *= c;
newValue += 0.5;
newValue *= 255;
if (newValue < 0)
newValue = 0;
if (newValue > 255)
newValue = 255;
destPixels[i] = (byte)newValue;
}
Run Code Online (Sandbox Code Playgroud)
我读了一次关于使用整数而不是浮点值来提高对比度的速度,但我再也找不到那篇文章了.
我尝试使用不安全的代码(指针),但实际上注意到速度降低.我假设这是因为代码使用嵌套for循环来迭代x和y而不是单个循环.
我需要在Android上的Java中计算两个图像之间的像素差异.问题是我的代码返回不准确的结果.
例如,我有3个非常相似的图片,但它们返回显着不同的结果,用于比较每个图片:pic1与pic2 = 1.71%; pic1 vs pic3 = 0.0045%; pic2 vs pic3 = 36.7%.
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
opt.inSampleSize = 5;
Bitmap mBitmap1 = BitmapFactory.decodeFile("/sdcard/pic1.jpg", opt);
Bitmap mBitmap2 = BitmapFactory.decodeFile("/sdcard/pic2.jpg", opt);
int intColor1 = 0;
int intColor2 = 0;
for (int x = 0; x < mBitmap1.getWidth(); x++) {
for (int y = 0; y < mBitmap1.getHeight(); y++) {
intColor1 = mBitmap1.getPixel(x, y);
intColor2 = mBitmap2.getPixel(x, y);
//System.out.print(" ("+ x + ","+ y +") c:" + …Run Code Online (Sandbox Code Playgroud)